Powershell v5-仅输出值

时间:2017-06-28 01:20:49

标签: powershell scripting

如何仅使用值导出以下内容。

目前它的导出方式如下:PC IPv4 Address. . . . . . . . . . . : 192.168.30.50.

我希望输出为:PC 192.168.30.50

脚本:

$ip = ipconfig | Select-String IPv4

$Host2 = Hostname

"$Host2 $ip" | Out-File "\\pc\c$\temp\Ipconfig.csv" -Append

1 个答案:

答案 0 :(得分:0)

试试这个:

$hostname = hostname
ipconfig | where {$_ -match 'IPv4.+\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' } >> $null
$ip=$Matches[1]
$Final_output = "$Hostname : $ip "
$Final_output