The code is: #Get the server list
$servers = Get-Content D:\server1.txt
#Run the commands for each server in the list
$infoColl = @()
$User = 'DOMAIN\USERNAME'
$pass= cat k:\securePassword.txt |ConvertTo-SecureString
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$Pass
Foreach ($s in $servers)
{
$CPUInfo = Get-WmiObject Win32_Processor -Credential $Credentials -ComputerName $s #Get CPU Information
$OSInfo = Get-WmiObject Win32_OperatingSystem -Credential $Credentials -ComputerName $s #Get OS Information
$bios = Get-WmiObject Win32_BIOS -Credential $Credentials -ComputerName $s
$update = (Get-HotFix -Credential $Credentials -ComputerName $s | Select-Object InstalledOn)[-1]
$arch = (Get-WmiObject Win32_OperatingSystem -Credential $Credentials -ComputerName $s).OSArchitecture
$memory = Get-WmiObject Win32_physicalmemory -Credential $Credentials -ComputerName $s
$disk = Get-WmiObject win32_logicaldisk -Credential $Credentials -ComputerName $s -Filter "Drivetype=3" | Select-Object DeviceID, VolumeName ,@{Label="Size";Expression={$_.Size / 1gb -as [int] }},@{Label="Free Size";Expression={$_.freespace / 1gb -as [int] }}
# you can get any application info along with this. For example, I mentioned eset antivirus:
$EsetEndpoint = Invoke-Command -Credential $Credentials -ComputerName $s -ScriptBlock {Get-CimInstance -ClassName Win32_Product -Filter "Name='ESET Endpoint Antivirus'"}
$EsetSecurity = Invoke-Command -Credential $Credentials -ComputerName $s -ScriptBlock {Get-CimInstance -ClassName Win32_Product -Filter "Name='ESET File Security'"}
$PhysicalMemory = Get-WmiObject CIM_PhysicalMemory -Credential $Credentials -ComputerName $s | Measure-Object -Property capacity -Sum | % { [Math]::Round(($_.sum / 1GB), 2) }
Foreach ($CPU in $CPUInfo)
{
$infoObject = New-Object PSObject
#The following add data to the infoObjects.
Add-Member -inputObject $infoObject -memberType NoteProperty -name "ServerName" -value $CPU.SystemName
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Service Tag" -value $bios.SerialNumber
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Manufacturer Computer" -value $bios.Manufacturer
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Bios_Version" -value $bios.Version
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Processor" -value $CPU.Name
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Architecture" -value $arch
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Operating System" -value $OSInfo.Caption
Add-Member -inputObject $infoObject -memberType NoteProperty -name "OS Version" -value $OSInfo.Version
Add-Member -inputObject $infoObject -memberType NoteProperty -name "RAM (GB)" -value $PhysicalMemory
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Used RAM Slot" -value $memory.count
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Disk Letter" -value $disk
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Windows Update Installed" -value $update.InstalledOn
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Eset Endpoint" -value $EsetEndpoint.Caption
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Eset Endpoint Version" -value $EsetEndpoint.Version
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Eset Endpoint Install Date" -value $EsetEndpoint.InstallDate
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Eset Security" -value $EsetSecurity.Caption
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Eset Security Version" -value $EsetSecurity.Version
Add-Member -inputObject $infoObject -memberType NoteProperty -name "Eset Security Install Date" -value $EsetSecurity.InstallDate
$infoObject #Output to the screen for a visual feedback.
$infoColl += $infoObject
}
}
$infoColl | Export-Csv -path D:\qwerty_$((Get-Date).ToString('MM-dd-yyyy')).csv -NoType #Export the results in csv file.
No comments:
Post a Comment