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

标签 authentication powershell https passwords microsoft-bits

我是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/

相关文章:

powershell - 仅在提供值时传递参数

Magento 为安全区域创建非 SSL 链接

ssl - Nginx 转发到其他 URL 时启用 HTTPS/SSL

c# - 将 http 重定向到 https 的问题

java - 如何让 AccountManager 处理每个用户名的多个帐户?

Android - Facebook 登录仅在第一次导致 onResume 错误

powershell - Powershell中快速简单的二进制连接文件

ios - iOS 应用程序内的新 field ?

iOS 偶尔会发送旧的 cookie

powershell - 使用一个属性比较两个CSV以比较另一个