我不是程序员/脚本作者。我只需要获取以下脚本即可将其写入文件:
[CmdletBinding()]
param ()
# Create a web client object
$webClient = New-Object System.Net.WebClient
# Returns the public IP address
$webClient.DownloadString('http://myip.dnsomatic.com/')
我已经尝试了out-file和export-csv,但是它写了一个空白文件。我敢肯定这很简单...但是一无所知对我来说很困难。
最佳答案
add-content cmdlet应该可以执行您想要的操作。
假设$webClient.DownloadString('http://myip.dnsomatic.com/')
返回一个字符串,请尝试:
Add-Content -Path $filename -Value $webClient.DownloadString('http://myip.dnsomatic.com/')
引用:
http://technet.microsoft.com/en-us/library/dd347594.aspx
关于file - 获取$ webclient.downloadstring以在Powershell中写入文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9365000/