簡體   English   中英

Powershell腳本從域中獲取計算機信息

[英]Powershell script to get computer info from domain

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

有人可以幫我解決嗎?

FLFormat-List用於格式化輸出。 您需要的是Select-ObjectSelect來過濾輸出數據。

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

這應該工作:

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

使用它代替當前行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM