Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于从域获取计算机信息的Powershell脚本_Powershell_Csv - Fatal编程技术网

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

用于从域获取计算机信息的Powershell脚本,powershell,csv,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\c

我的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

有人能帮我解决吗?

FL
格式列表
用于格式化输出。您需要的是
Select Object
Select
来过滤输出数据

$computerSN = Get-WmiObject Win32_bios -ComputerName $_.Name | Select-Object SerialNumber
这一条应该有效:

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

使用此行而不是当前行。

$computerSN=Get WmiObject Win32\u bios-ComputerName$\uName
我只需要获取序列号。我是否应该更改“序列号”行,使其只输出序列号?Get-WmiObject Win32_bios提供了大量信息我在一两个月前编写了一个脚本,从WMI/CIM获取了大量信息,并使其非常漂亮。它仍然缺少portscan函数,但它中的所有其他功能都已完成。您可能会在其中找到一些用处,或者至少在代码中找到一些用处。伟大的非常感谢你。我现在可以在输出文件中看到序列号。