2013-03-27 1 views
0

PowerShell 스크립팅을 처음 사용합니다. 나는 MS 문서에 어려움을 겪고 있으며 몇 가지 예제를 찾아야한다.Powershell BitsTransfer https 기본 인증 구문

BitsTransfer 스크립트를 사용하여 ntis.gov에서 매주 다운로드하는 대형 txt 파일을 자동화하려고합니다. SSIS는. NET 코드를 작성하지 않으면이 작업을 수행 할 수 없기 때문에 .ps1 스크립트를 사용하고 있습니다.

NTIS에서 발급 한 사용자 이름 및 암호와 함께 https :를 통해이 텍스트 파일에 액세스 할 수 있습니다. 암호를 인증 문자열에 지정하려면 어떻게해야합니까? 나는 이것이 나쁜 습관이라는 것을 알고있다. 이 작업을 수행하는 더 좋은 방법이 있습니까? 당신은 비 대화식 모드에서 자격 증명을 제공해야 할 때

내 스크립트가 this-

$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} 
    } 

답변

2

처럼 보이는, 다음과 같은 방법으로 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 
+0

고맙습니다. 매우 도움이됩니다. 나는 당신의 모범이 다른 사람들을 도울 것이라고 확신합니다. – Colin