1
我想將外部IP地址與當前硬件信息輸出文件組合在一起。將新項目添加到XML輸出文件
PC信息
#lists computer information
$cpu = Get-WmiObject -Class Win32_Processor
$mb = Get-WmiObject -Class Win32_BaseBoard
$bios = Get-WmiObject -Class Win32_BIOS -ComputerName .
#$user = Get-WmiObject -Class Win32_ComputerSystem
$last = Get-WmiObject -class Win32_NetworkLoginProfile |
Where {($_.NumberOfLogons -gt 0) -and ($_.NumberOfLogons -lt 65535)} |
Select-Object Name,@{label='LastLogon';expression={$_.ConvertToDateTime($_.LastLogon)}},NumberOfLogons
$props = @{
"Name" = $cpu.Name
"Description" = $cpu.Description
"MB Manufacturer" = $mb.Manufacturer
"MB Product" = $mb.Product
"Bios Verison" = $bios.SMBIOSBIOSVersion
"Bios Manufacturer" = $bios.Manufacturer
"Bios Serial" = $bios.SerialNumber
"~Last Logon" = $last
}
New-Object PSObject -Property $props | Out-File c:\Windows\Script\PS_Output3.xml
外部IP地址
$wc=New-Object net.webclient;
$wc.downloadstring("http://checkip.dyndns.com") -replace "[^\d\.]"
更新 最後一個問題:我怎麼能組織名單?
那麼你並不需要XML輸出,你接受了一個基於字符串輸出答案 – Matt
@馬特。你是對的。它不需要在XML輸出 –