gpt4 book ai didi

authentication - Powershell BitsTransfer https基本身份验证语法

转载 作者:行者123 更新时间:2023-12-02 23:04:58 24 4
gpt4 key购买 nike

我是PowerShell脚本的新手。我在MS文档方面苦苦挣扎,几乎找不到可以使用的示例。

我正在尝试使用BitsTransfer脚本每周自动从ntis.gov下载大型txt文件。我正在使用.ps1脚本,因为显然SSIS如果不编写.NET代码就无法做到这一点。

通过https:使用NTIS颁发的用户名和密码访问此文本文件。如何在认证字符串中指定(硬编码)密码?我知道这是不好的做法。有一个更好的方法吗?

我的脚本看起来像这样-

    $date= Get-Date -format yyMMdd
Import-Module BitsTransfer
$Job = Start-BitsTransfer `
-DisplayName DMFweeklytrans `
-ProxyUsage AutoDetect `
-Source https://dmf.ntis.gov/dmldata/weekly/WA$date `
-Destination D:\Test.txt `
-Authentication Basic `
-Credential "myIssuedUsername" `
-Asynchronous

While (($Job.JobState -eq "Transferring") -or ($Job.JobState -eq "Connecting")) {sleep 5}
Switch($Job.JobState)
{
"Transfer Completed" {Complete-BitsTransfer -BitsJobs $Jobs}
default {$Job | Format-List}
}

最佳答案

当您必须以非交互方式提供凭据时,可以通过以下方式创建PSCredential对象。

$secpasswd = ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force
$yourcreds = New-Object System.Management.Automation.PSCredential ("username", $secpasswd)

$Job = Start-BitsTransfer `
-DisplayName DMFweeklytrans `
-ProxyUsage AutoDetect `
-Source https://dmf.ntis.gov/dmldata/weekly/WA$date `
-Destination D:\Test.txt `
-Authentication Basic `
-Credential $yourcreds `
-Asynchronous

关于authentication - Powershell BitsTransfer https基本身份验证语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15664210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com