#get list of hosts
$hosts=get-content "h:\scripts\hosts.txt"
$P2VCandidates="h:\scripts\ScriptOutput\P2VCandidatesOutput_$((get-date).toString('MM-dd-yyyy_hh.mmtt')).csv"
$tableInfo=@("DeviceId", "VolumeName", @{Label="FreeSpace(GB)"; Alignment="right"; Expression={"{0:N2}" -f ($_.FreeSpace/1GB)}}, @{Label="Size(GB)"; Alignment="right"; Expression={"{0:N2}" -f ($_.size/1GB)}})
#$hosts
foreach($server in $hosts)
{
# WMI Commands
$os = Get-WmiObject Win32_OperatingSystem –computerName $server -ErrorAction SilentlyContinue
$machine = get-wmiobject win32_computersystem –computerName $server -ErrorAction SilentlyContinue
$bios = get-wmiobject Win32_bios -ComputerName $server -ErrorAction SilentlyContinue
# add a filter to only return the first CPU object - this is kinda bastard but generally CPUs will all be the same :)
$cpu = Get-WmiObject Win32_Processor –computerName $server -ErrorAction SilentlyContinue | select-object -first 1
#compute RAM in GB
$memory = get-wmiobject Win32_ComputerSystem –computerName $server
$memorygb = [Math]::Round($memory.TotalPhysicalMemory/1GB)
# IP Info
$addr = 0
$IPconfigset = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $server
foreach ($IPConfig in $IPConfigSet) {
if ($Ipconfig.IPaddress) {
foreach ($addr in $Ipconfig.Ipaddress) {
Out-String
}
}
}
#end IP
#Disk Info
$totalsize = 0
$totalfree = 0
#debug - what are we set to?
#$totalsize
#$totalfree
# Get fixed drive info
$disks = Get-WmiObject -ComputerName $server -Class Win32_LogicalDisk -Filter "DriveType = 3";
foreach($disk in $disks)
{
$deviceID = $disk.DeviceID;
[float]$size = $disk.Size;
[float]$freespace = $disk.FreeSpace;
#debug - what server?
#$server
#debug - what size did we find?
#write-host current disk ($size/1GB)
#debug - what is the current total?
#write-host total disk ($totalsize/1GB)
$totalsize += $disk.size
$totalfree += $disk.FreeSpace
}
#end disk
# Formatting the output
$output = New-Object PSObject
$output | Add-Member NoteProperty Name $server
$output | Add-Member NoteProperty NTDomain $machine.Domain
$output | Add-Member NoteProperty Manufacturer $machine.Manufacturer
$output | Add-Member NoteProperty Model $machine.Model
$output | Add-Member NoteProperty Serial $bios.SerialNumber
$output | Add-Member NoteProperty Type $machine.SystemType
#$output | Add-Member NoteProperty 64bit $cpu
$output | Add-Member NoteProperty TotalRAM $memorygb
$output | Add-Member NoteProperty NumberOfProcessors $machine.NumberOfProcessors
$output | Add-Member NoteProperty CPUName $cpu.Name
$output | Add-Member NoteProperty CPUSpeed $cpu.CurrentClockSpeed
$output | Add-Member NoteProperty IPInfo $addr
$output | Add-Member NoteProperty TotalDisk ($totalsize/1GB)
$output | Add-Member NoteProperty FreeDisk ($totalfree/1GB)
$output | Add-Member NoteProperty OSName $os.caption
$output | Add-Member NoteProperty ServicePack $os.CSDVersion
Write-Output $output | Export-Csv $P2VCandidates -noType -Append
}
No comments:
Post a Comment