2015-06-20 51 views
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\.]" 

更新 最後一個問題:我怎麼能組織名單?

+1

那麼你並不需要XML輸出,你接受了一個基於字符串輸出答案 – Matt

+0

@馬特。你是對的。它不需要在XML輸出 –

回答

0

像這樣的東西可能會有所幫助:

#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 
$DyDNS = Invoke-WebRequest http://checkip.dyndns.com/ -DisableKeepAlive 
$Dyreg = $DyDNS.RawContent -match '\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b' 
$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 
    "DNS"     = $matches[0] 

    } 
New-Object PSObject -Property $props | Out-File C:\test.csv 
+0

你這個人謝謝你。花了很長時間,試圖找出大聲笑 –