##Load server list. A text file containing one server name per line. $serverList = Get-Content -Path C:\temp\server.txt $logfile = "C:\temp\logfile.txt" Add-Content $logfile -value "..................................................." Add-Content $logfile -value "New log file $(Get-Date)" $c = Get-Credential ##A loop that is run for each server foreach ($server in $serverList) { ##check whether the server answer via ping. if (Test-Connection -ComputerName $server -Quiet -Count 1) { ##If the server can be reached via ping, then: Add-Content $logfile -value "...Server $($server)..." $computerInfo = Get-WMIObject Win32_ComputerSystem -computerName $server -Credential $c $osInfo = Get-WMIObject Win32_OperatingSystem -computername $server -Credential $c $bootTime = [string]$osInfo.ConvertToDateTime ($osInfo.LastBootUpTime) #If the manufacturer is Microsoft or VMWare if($computerInfo.Manufacturer -eq "Microsoft Corporation" -and $computerInfo.Model -eq "Virtual Machine") { $type = "Hyper-V Virtual Machine" } elseif($computerInfo.Manufacturer -eq "VMware, Inc." -and $computerInfo.Model -eq "VMware Virtual Platform") { $type = "VMWare Virtual Machine" } else { $type = "physical machine" } ##Computer Info Add-Content $logfile -value "Member of $($computerInfo.Domain). Made by $($computerInfo.Manufacturer)." Add-Content $logfile -value "It is a $($type)." Add-Content $logfile -value "RAM: $($computer Info.TotalPhysicalMemory/1024/1024) MByte" ##OSInfo Add-Content $logfile -value "Running on $($osInfo.Caption), build $($osInfo.BuildNumber) - with $($osInfo.OSArchitecture)" Add-Content $logfile -value "Installed on $($osInfo.ConvertToDateTime($osInfo.Install Date))" Add-Content $logfile -value "Registered user: $($osInfo.RegisteredUser)" Add-Content $logfile -value "Last started $($bootTime)" } else { Write host "The server $($server) cannot be reached. We proceed with the next..." } }