Re: 2 CSV files - combine into one CSV
Posted: Thu Oct 03, 2013 5:33 pm
Couple quesions, runing get-qadcomputer to get the description and managed by throws an error - "get-qadcomputer" is not recognized as a cmd. Also, adding the windows license status works for the 2008 servers, but the 2003 servers uses a different -class, how can i tell it to differentiate between both operating systems?
$InventoryCSVb = "D:\Powershell\Inventory\code_testing_inventory\code_testing_inventoryb.csv"
$RemoteServerSessions = "D:\Powershell\Inventory\code_testing_inventory\RemoteSrvSessions.txt"
$Block = {
$OperatingSystem = gwmi win32_operatingsystem
$ComputerSystem = gwmi win32_computersystem
$TimeZone = gwmi Win32_TimeZone
$NIC = gwmi win32_NetworkAdapterConfiguration | where {$_.IPEnabled -eq "True"} | select IPAddress
$License = gwmi SoftwareLicensingProduct | Where-Object {$_.productkeyid -ne $null} | select LicenseStatus
$ManagedBy = Get-QADComputer -searchroot 'site' | select ManagedBy
#$License = gwmi Win32_WindowsProductActivation
$Description =
$Properties=@{
Name = $OperatingSystem.CSName
OperatingSystem = $OperatingSystem.Caption
ServicePack= $OperatingSystem.CSDVersion
PhysicalMemory = [math]::round($ComputerSystem.TotalPhysicalMemory/1GB)
NumberOfProcessors = $ComputerSystem.NumberOfProcessors
LastBootTIme = $OperatingSystem.ConvertToDateTime($OperatingSystem.LastBootupTime)
IPAddress = $NIC.IPAddress
TimeZone = $TimeZone.Caption
LicenseStatus = $License.LicenseStatus
ManagedBy = $ManagedBy.ManagedBy
Description
}
New-Object PsObject -Property $Properties
}
$sessions = Get-QADComputer -searchroot 'site' | `
Where-Object { $_.description -notlike "ClusterResource*" -and $_.description -notlike "Disaster*" -and $_.accountisdisabled -eq $False -and $_.description -notlike "*Decom?" } | `
ForEach-Object { new-pssession -ComputerName $_.Name
}
Invoke-Command -ScriptBlock $block -Session $sessions | Select 'Name','OperatingSystem', 'ServicePack','PhysicalMemory','NumberOfProcessors','LastBootTime','TimeZone','IPAddress','LicenseStatus','ManagedBy','Description' | Export-Csv $InventoryCSVb -NoTypeInformation
$sessions | Remove-PSSession
$InventoryCSVb = "D:\Powershell\Inventory\code_testing_inventory\code_testing_inventoryb.csv"
$RemoteServerSessions = "D:\Powershell\Inventory\code_testing_inventory\RemoteSrvSessions.txt"
$Block = {
$OperatingSystem = gwmi win32_operatingsystem
$ComputerSystem = gwmi win32_computersystem
$TimeZone = gwmi Win32_TimeZone
$NIC = gwmi win32_NetworkAdapterConfiguration | where {$_.IPEnabled -eq "True"} | select IPAddress
$License = gwmi SoftwareLicensingProduct | Where-Object {$_.productkeyid -ne $null} | select LicenseStatus
$ManagedBy = Get-QADComputer -searchroot 'site' | select ManagedBy
#$License = gwmi Win32_WindowsProductActivation
$Description =
$Properties=@{
Name = $OperatingSystem.CSName
OperatingSystem = $OperatingSystem.Caption
ServicePack= $OperatingSystem.CSDVersion
PhysicalMemory = [math]::round($ComputerSystem.TotalPhysicalMemory/1GB)
NumberOfProcessors = $ComputerSystem.NumberOfProcessors
LastBootTIme = $OperatingSystem.ConvertToDateTime($OperatingSystem.LastBootupTime)
IPAddress = $NIC.IPAddress
TimeZone = $TimeZone.Caption
LicenseStatus = $License.LicenseStatus
ManagedBy = $ManagedBy.ManagedBy
Description
}
New-Object PsObject -Property $Properties
}
$sessions = Get-QADComputer -searchroot 'site' | `
Where-Object { $_.description -notlike "ClusterResource*" -and $_.description -notlike "Disaster*" -and $_.accountisdisabled -eq $False -and $_.description -notlike "*Decom?" } | `
ForEach-Object { new-pssession -ComputerName $_.Name
}
Invoke-Command -ScriptBlock $block -Session $sessions | Select 'Name','OperatingSystem', 'ServicePack','PhysicalMemory','NumberOfProcessors','LastBootTime','TimeZone','IPAddress','LicenseStatus','ManagedBy','Description' | Export-Csv $InventoryCSVb -NoTypeInformation
$sessions | Remove-PSSession