Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否在powershell中查找外部IP地址和日志地址号?_Powershell_Logging_Ip_External_Ip Address - Fatal编程技术网

是否在powershell中查找外部IP地址和日志地址号?

是否在powershell中查找外部IP地址和日志地址号?,powershell,logging,ip,external,ip-address,Powershell,Logging,Ip,External,Ip Address,我制作了一个powershell脚本来查找我的外部IP地址。以下是我目前掌握的代码: $wc=New-Object net.webclient $wc.downloadstring("http://checkip.dyndns.com") -replace "[^\d\.]" >External_IP.txt 我打算每周运行这个脚本,并希望保留一个IP地址更改日志。目前,它将外部IP地址保存在名为external_IP.txt的文本文件中。当运行多次时,它不会向文本文件添加新行 有人能告

我制作了一个powershell脚本来查找我的外部IP地址。以下是我目前掌握的代码:

$wc=New-Object net.webclient
$wc.downloadstring("http://checkip.dyndns.com") -replace "[^\d\.]" >External_IP.txt
我打算每周运行这个脚本,并希望保留一个IP地址更改日志。目前,它将外部IP地址保存在名为external_IP.txt的文本文件中。当运行多次时,它不会向文本文件添加新行


有人能告诉我这方面的信息吗?=)

由于您正在使用
写入文件,请尝试使用
>
,如果文件存在,则应将其附加到该文件。

将管道连接到
Out file
cmdlet并指定附加开关

... -replace "[^\d\.]" | Out-File External_IP.txt -Append

Shays在PowerShell V3中的回答是正确的
我不确定你是否在v2中有he-append选项,请解释你的答案,并解释为什么代码会通过对答案进行加密来工作。
$source = "http://ammaso.com/IP"
$client = new-object System.Net.WebClient
$webpage = $client.downloadString($source)
$obj = New-Object Object
$obj | Add-Member Noteproperty externalIP -value $webpage
$obj