Я довольно новичок в сценариях Powershell и играю со сценарием, который я нашел в Интернете, который запрашивает все системы в моем домене и выводит биты аппаратной информации в CSV. Сценарий:
$testcomputers = Get-Content -Path 'C:\scripts\computers.txt'
$exportLocation = 'C:\scripts\pcInventory.csv'
foreach ($computer in $testcomputers) {
if (Test-Connection -ComputerName $computer -Quiet -count 2){
Add-Content -value $computer -path c:\scripts\livePCs.txt
}else{
Add-Content -value $computer -path c:\scripts\deadPCs.txt
}
}
$computers = Get-Content -Path 'C:\scripts\livePCs.txt'
foreach ($computer in $computers) {
$Bios = Win32_computerSystem -Computername $Computer
$Sysbuild = Get-WmiObGet-WmiObject win32_bios -Computername $Computer
$Hardware = Get-WmiObjectject Win32_WmiSetting -Computername $Computer
$OS = Get-WmiObject Win32_OperatingSystem -Computername $Computer
$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | Where-Object {$_.IPEnabled}
$driveSpace = Get-WmiObject win32_volume -computername $Computer -Filter 'drivetype = 3' |
Select-Object PScomputerName, driveletter, label, @{LABEL='GBfreespace';EXPRESSION={'{0:N2}' -f($_.freespace/1GB)} } |
Where-Object { $_.driveletter -match 'C:' }
$cpu = Get-WmiObject Win32_Processor -computername $computer
$username = Get-ChildItem "\\$computer\c$\Users" | Sort-Object LastWriteTime -Descending | Select-Object Name, LastWriteTime -first 1
$totalMemory = [math]::round($Hardware.TotalPhysicalMemory/1024/1024/1024, 2)
$lastBoot = $OS.ConvertToDateTime($OS.LastBootUpTime)
$IPAddress = $Networks.IpAddress[0]
$MACAddress = $Networks.MACAddress
$systemBios = $Bios.serialnumber
$OutputObj = New-Object -Type PSObject
$OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()
$OutputObj | Add-Member -MemberType NoteProperty -Name Manufacturer -Value $Hardware.Manufacturer
$OutputObj | Add-Member -MemberType NoteProperty -Name Model -Value $Hardware.Model
$OutputObj | Add-Member -MemberType NoteProperty -Name Processor_Type -Value $cpu.Name
$OutputObj | Add-Member -MemberType NoteProperty -Name System_Type -Value $Hardware.SystemType
$OutputObj | Add-Member -MemberType NoteProperty -Name Operating_System -Value $OS.Caption
$OutputObj | Add-Member -MemberType NoteProperty -Name Operating_System_Version -Value $OS.version
$OutputObj | Add-Member -MemberType NoteProperty -Name Operating_System_BuildVersion -Value $SysBuild.BuildVersion
$OutputObj | Add-Member -MemberType NoteProperty -Name Serial_Number -Value $systemBios
$OutputObj | Add-Member -MemberType NoteProperty -Name IP_Address -Value $IPAddress
$OutputObj | Add-Member -MemberType NoteProperty -Name MAC_Address -Value $MACAddress
$OutputObj | Add-Member -MemberType NoteProperty -Name Last_User -Value $username.Name
$OutputObj | Add-Member -MemberType NoteProperty -Name User_Last_Login -Value $username.LastWriteTime
$OutputObj | Add-Member -MemberType NoteProperty -Name C:_FreeSpace_GB -Value $driveSpace.GBfreespace
$OutputObj | Add-Member -MemberType NoteProperty -Name Total_Memory_GB -Value $totalMemory
$OutputObj | Add-Member -MemberType NoteProperty -Name Last_ReBoot -Value $lastboot
$OutputObj | Export-Csv $exportLocation -Append -NoTypeInformation
}
Когда я запускаю сценарий, я получаю ошибки ниже и не совсем уверен, как их исправить. Я также заметил, что строка, предназначенная для вывода ОЗУ системы, всегда выдает 0. Любое руководство будет высоко ценится. Я использую Powershell 3 на Windows 7, если это что-то меняет.
Win32_computerSystem : The term 'Win32_computerSystem' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
Get-WmiObGet-WmiObject : The term 'Get-WmiObGet-WmiObject' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
Get-WmiObjectject : The term 'Get-WmiObjectject' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.