Authentication Powershell BitsTransfer https基本身份验证语法
我是PowerShell脚本编写新手。我正在努力使用MS文档,并找到了一些可以使用的示例 我正在尝试使用BitsTransfer脚本自动从ntis.gov每周下载一个大型txt文件。我之所以使用.ps1脚本,显然是因为SSIS不编写.NET代码就无法做到这一点 通过https:访问此文本文件,并使用NTIS颁发的用户名和密码。如何在身份验证字符串中指定(硬代码)密码?我知道这是个坏习惯。有更好的方法吗 我的脚本是这样的-Authentication Powershell BitsTransfer https基本身份验证语法,authentication,powershell,https,passwords,microsoft-bits,Authentication,Powershell,Https,Passwords,Microsoft Bits,我是PowerShell脚本编写新手。我正在努力使用MS文档,并找到了一些可以使用的示例 我正在尝试使用BitsTransfer脚本自动从ntis.gov每周下载一个大型txt文件。我之所以使用.ps1脚本,显然是因为SSIS不编写.NET代码就无法做到这一点 通过https:访问此文本文件,并使用NTIS颁发的用户名和密码。如何在身份验证字符串中指定(硬代码)密码?我知道这是个坏习惯。有更好的方法吗 我的脚本是这样的- $date= Get-Date -format yyMMdd
$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
非常感谢。非常有用。我相信你的例子也会帮助其他人。有没有办法直接设置标题?例如,Azure Devops希望将令牌(PAT)设置为授权标头。它基本上是一个base-64编码的字符串,但不是:。@Marc你有没有尝试过像这样的东西:
$MyPat='yourPAT'$B64Pat=[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(“:$MyPat”)
和授权:Basic${B64\u PAT