尝试查询非 Windows 本机程序 (dell racadm) 信息并将字符串格式化为包含其他信息的 csv 文件。 一切正常,直到我到达 iDracIP 并且它在 csv 文件中返回空白。 我知道我的语法很糟糕,但我不知道使用什么命令来获取“IP 地址”字符串并将其通过管道传输到 csv 文件中。 我尝试过选择对象、获取项目属性。
$logregion =“测试”
$host.ui.RawUI.WindowTitle = "IP FQDN - $logRegion"
$currentdate = get-date -f yyyy-MM-dd
function get_info_func {
$a = Get-Content "$PSScriptRoot\servers.txt"
$get_info_array = @()
foreach ($i in $a){
write-host $i
$array = New-Object PSObject
$array | Add-Member -type NoteProperty -Name "Name From List" -Value $i
$array | Add-Member -type NoteProperty -Name "Host Name" -Value (Get-WmiObject -Class Win32_ComputerSystem -computername $i | Select-Object -expandproperty dnshostname)
$array | Add-Member -type NoteProperty -Name "Domain" -Value (Get-WmiObject -Class Win32_ComputerSystem -computername $i | Select-Object -expandproperty Domain)
$array | Add-Member -type NoteProperty -Name "IPAddress" -Value ([string](Get-WmiObject -Class Win32_NetworkAdapterConfiguration -computername $i | Select-object -expandproperty IPAddress) )
$array | Add-Member -type NoteProperty -Name "IpSubnet" -Value ([string](Get-WmiObject -Class Win32_NetworkAdapterConfiguration -computername $i | Select-object -expandproperty IpSubnet) )
$array | Add-Member -type NoteProperty -Name "DefaultIPGateway" -Value ([string](Get-WmiObject -Class Win32_NetworkAdapterConfiguration -computername $i | Select-object -expandproperty DefaultIPGateway) )
$array | Add-Member -type NoteProperty -Name "DNSServerSearchOrder" -Value ([string](Get-WmiObject -Class Win32_NetworkAdapterConfiguration -computername $i | Select-object -expandproperty DNSServerSearchOrder) )
$array | Add-Member -type NoteProperty -Name "Mac Address" -Value ([string](Get-WmiObject -Class Win32_NetworkAdapterConfiguration -computername $i | Select-object -expandproperty MACAddress) )
$array | Add-Member -type NoteProperty -Name "OS" -Value (Get-WmiObject -class Win32_OperatingSystem -computername $i | Select-Object -expandproperty Caption)
$array | Add-Member -type NoteProperty -Name "MODEL" -Value (Get-WmiObject -Class Win32_ComputerSystem -computername $i | Select-Object -expandproperty Model)
$array | Add-Member -type NoteProperty -Name "Serial Number" -Value (Get-WmiObject -class WIN32_systemenclosure -computername $i | Select-Object -expandproperty SerialNumber)
$array | Add-Member -type NoteProperty -Name "iDrac IP" -Value ([string](Invoke-Command -scriptblock { racadm.exe getniccfg } -computername $i) | Select-Object -expandproperty "IP Address")
$get_info_array += $array
}
$get_info_array | Export-Csv "$PSScriptRoot\IPinfo_$($logregion)_$(get-date -f yyyy-MM-dd).csv" -NoTypeInformation -append
}#end function
& get_info_func
这应该有效
@(racadm.exe getniccfg).Where({$_ -like "*IP Address*"}) -replace '^.*?(\d+\.\d+\.\d+\.\d+).*$', '$1'