file - 获取$ webclient.downloadstring以在Powershell中写入文本文件

标签 file powershell export

我不是程序员/脚本作者。我只需要获取以下脚本即可将其写入文件:

[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/

相关文章:

file - 使用 awk/sed 删除双新行

linux - 自定义提示在 Ubuntu 上的 PowerShell Core 6.0 中打印两次

azure - 我们可以使用任何命令/脚本/ARM 模板创建 Azure 服务连接吗?

vba - 将 Excel 工作表导出到 Access 表 (.accdb)

java如何实时读取文件

c++ - 如果 C++ 中已经存在,如何通过增加其索引来创建新文件夹

php - 重命名文件(如果已存在)- php 上传系统

xml - 为什么 SelectSingleNode 返回 null 对象?

java - 导出带有图像的 Jar

eclipse - 将 "External Tool Configurations"从一个 Eclipse 安装转移到另一个安装的快速方法?