Powershell脚本从域获取计算机信息

时间:2017-04-28 01:17:07

标签: powershell csv

我的PowerShell脚本存在一些问题。当我运行它时,SN(序列号)部分不会从计算机获取任何信息,但是,当我运行命令" Get-WmiObject Win32_bios | fl SerialNumber"在我的电脑上运行。

# Get the list of all computer names and export to CSV file
Get-ADComputer -Filter * | select Name | 
    Export-Csv -Path 'C:\temp\computers.csv' -NoTypeInformation

# Import the computer names from CSV file and get the system information
$computers = Import-Csv “C:\Temp\computers.csv” | ForEach {

$computerSystem = Get-WmiObject Win32_ComputerSystem -ComputerName $_.Name
$computerOS = Get-WmiObject Win32_OperatingSystem -ComputerName $_.Name
$computerCPU = Get-WmiObject Win32_Processor -ComputerName $_.Name
$computerSN = Get-WmiObject Win32_bios | fl SerialNumber -ComputerName $_.Name

[PSCustomObject]@{
    'PCName' = $computerSystem.Name    
    'Model' = $computerSystem.Model   
    'RAM' = "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB)    
    'CPU' = $computerCPU.Name    
    'OS' = $computerOS.caption   
    'SN' =$computerSN.SerialNumber
    'User' = $computerSystem.UserName    
}

} | Export-Csv 'C:\Temp\system-info.csv' -NoTypeInformation

有人可以帮我解决一下吗?

2 个答案:

答案 0 :(得分:0)

FLFormat-List用于格式化输出。您需要Select-ObjectSelect来过滤输出数据。

$computerSN = Get-WmiObject Win32_bios -ComputerName $_.Name | Select-Object SerialNumber

答案 1 :(得分:0)

这个应该有效:

Get-WmiObject Win32_bios -ComputerName $_.Name | select SerialNumber

使用此代替当前行。

相关问题