【发布时间】:2017-07-12 20:42:03
【问题描述】:
我目前正在尝试指示新创建的 Windows shell 通过 autounattend.xml 文件下载 powershell 脚本。使用这种技术,我需要一个班轮来完成工作。
我以前可以使用这种单线从公共环境下载它们:
<Path>powershell -NoLogo -Command "((new-object System.Net.WebClient).DownloadFile('https://some.remote.public.location/myfile.ps1', 'c:\Windows\Temp\myfile.ps1')"</Path>
但现在我需要提供适当的凭据才能从私人位置下载我的文件。我尝试了以下方法,但它不起作用:
<Path>powershell -NoLogo -Command "((new-object System.Net.WebClient).Credentials = new-object System.Net.NetworkCredential("user123", "password123")).DownloadFile('https://some.remote.private.location/myfile.ps1', 'c:\Windows\Temp\myfile.ps1')"</Path>
(我是powershell的菜鸟:/)
我怎样才能在一行中为 DownloadFile 方法提供正确的凭据?
或者还有其他更适合这项工作的命令吗?
谢谢。
【问题讨论】:
标签: windows powershell automation