将新项添加到XML输出文件中

时间:2015-06-20 01:21:09

标签: powershell

我想将外部IP地址与当前硬件信息输出文件合并。

电脑信息

#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 个答案:

答案 0 :(得分: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