Need help from the PS gurus out there!I'm new to PS and I'm trying to create a script that dumps some basic server info to a CSV file. Now I can get it to work and gather most all my info I need and create the CSV. But, I cannot seem to return the hard drive info I'm trying to gather. Nothing goes in to the columns, they are blank. If you copy this script, change to your SQL Server, test environment not live :), and execute, it should be pretty self evident what I'm trying to do and what is missing.Any help is greatly appreciated!!!Here is my script thus-far:[code="other"][cmdletbinding()]param ( [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] [string[]]$ComputerName = "YOURSERVERNAME") begin {}process { foreach ($Computer in $ComputerName) { if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) { $Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled} $Memory = Get-WmiObject Win32_ComputerSystem -ComputerName $Computer | Select TotalPhysicalMemory, Manufacturer, Model $Processor = Get-WMIObject Win32_Processor -ComputerName $Computer | Select Name $DriveSize = Get-WMIObject Win32_LogicalDisk -ComputerName $Computer | Select Name, Size, FreeSpace $SQLVersion = invoke-sqlcmd -query "select @@version" -ServerInstance $Computer | Select Column1 $Connections = invoke-sqlcmd -query "SELECT COUNT(dbid) as TotalConnections FROM sys.sysprocesses WHERE dbid > 0" -ServerInstance $Computer | Select TotalConnections foreach ($Network in $Networks) { $IPAddress = $Network.IpAddress[0] $mem = $memory.TotalPhysicalMemory / 1GB $Manufacturer = $memory.Manufacturer $Model = $memory.Model $ProcessorSpeed = $Processor.Name $DriveName = $DriveSize.Name $DriveSizeTotal = $DriveSize.Size / 1GB $DriveSizeFree = $DirveSize.FreeSpace / 1GB $SQLVersionNo = $SQLVersion.Column1 $ConnectionsNo = $Connections.TotalConnections $OutputObj = New-Object PSObject $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper() $OutputObj | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IPAddress $OutputObj | Add-Member -MemberType NoteProperty -Name Manufacturer -Value $Manufacturer $OutputObj | Add-Member -MemberType NoteProperty -Name ServerModel -Value $Model $OutputObj | Add-Member -MemberType NoteProperty -Name TotalPhysicalMemoryGB -Value $mem $OutputObj | Add-Member -MemberType NoteProperty -Name Processor -Value $ProcessorSpeed $OutputObj | Add-Member -MemberType NoteProperty -Name DriveName -Value $DriveSize.Name $OutputObj | Add-Member -MemberType NoteProperty -Name DriveSizeTotal -Value $DriveSize.Size $OutputObj | Add-Member -MemberType NoteProperty -Name DriveSizeFree -Value $DriveSize.FreeSpace $OutputObj | Add-Member -MemberType NoteProperty -Name SQLVersion -Value $SQLVersionNo $OutputObj | Add-Member -MemberType NoteProperty -Name NumberOfConnections -Value $ConnectionsNo $OutputObj | Export-CSV -Path “C:\TEMP\report.csv” -notype } } }} end {}[/code]
↧