Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, July 11, 2019 5:59 PM
So I am trying to learn powershell, and I learned about BitsTransfer which works great without credentials, but can't seem to get it to work with credentials. Any help is appreciated.
Here is my code:
Import-Module BitsTransfer
$FileArray = @("File1.zip", File2.zip) #Future use
$username = "MyUserName"
$password = "MyPassword"
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol.toString() + ', ' + [Net.SecurityProtocolType]::Tls12
$url = "https://mywebsite.com/Usr/" + $file1.zip
$output = "$PSScriptRoot\20meg.test"
Start-BitsTransfer -Credential '$username','$password' -Source $url -Destination $output
$start_time = Get-Date
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"
All replies (10)
Thursday, July 11, 2019 9:07 PM ✅Answered | 1 vote
PsCredential is only for authentication in Windows domains or to servers that support standard authentication types. It is not intended for authentication to web sites that may have complex multi-factor authentication.
First try removing "-Authentication" and let the service and the server negotiate the type.
\(ツ)_/
Thursday, July 11, 2019 7:08 PM
you need to create a credential object.
See help:
help start-bitstransfer -full
Always read the help before asking a question. 90% of the time the answer is in the help.
\(ツ)_/
Thursday, July 11, 2019 8:00 PM
The help mentions usernames but not the password.
-Credential <PSCredential>
Specifies the credentials to use to authenticate the user to the server that is specified in the value of the
Source parameter. The default is the current user.
Type a user name, such as "User01", "Domain01\User01", or "[email protected]". Or, use the Get-Credential
cmdlet to create the value for this parameter. When you type a user name, you are prompted for a password.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
Thursday, July 11, 2019 8:02 PM | 1 vote
help get-credential -online
Search for articles on how to programmatically create a credential. There are hundreds of articles.
\(ツ)_/
Thursday, July 11, 2019 8:08 PM
I do not want to use the get credential. I do not want to type in username and password.
Believe me, I have searched for a solution before asking, but haven't found a solution
Thursday, July 11, 2019 8:19 PM | 1 vote
You didn't search much.
Try searching for PsCredential as it notes in the help. I searched and it was the first item listed. Go back and read the help carefully.
We cannot teach you PowerShell and we cannot help you learn how to use a search engine.
Without taking the time to learn basic PowerShell you will be forever lost if you are not a trained and certified Windows technician at a OS and network level or you have no formal programming background.
Microsoft Virtual Academy - Getting Started with Microsoft PowerShell
\(ツ)_/
Thursday, July 11, 2019 9:01 PM
You didn't search much.
Try searching for PsCredential as it notes in the help. I searched and it was the first item listed. Go back and read the help carefully.
We cannot teach you PowerShell and we cannot help you learn how to use a search engine.
Without taking the time to learn basic PowerShell you will be forever lost if you are not a trained and certified Windows technician at a OS and network level or you have no formal programming background.
Microsoft Virtual Academy - Getting Started with Microsoft PowerShell
\(ツ)_/
I do have background in VB.net, SQL, and PressTalk. Primarily working with data files. I am working on learning Powershell, and do appreciate the help.
Anyway when I use the PSCredential I get this error:
Start-BitsTransfer : HTTP status 401: The requested resource requires user authentication.
At E:\NewDownloadtst.ps1:13 char:1
- Start-BitsTransfer -Authentication Basic -Credential $Cred -DisplayNa ...
-
+ CategoryInfo : InvalidOperation: (:) [Start-BitsTransfer], Exception
+ FullyQualifiedErrorId : StartBitsTransferCOMException,Microsoft.BackgroundIntelligentTransfer.Management.NewBitsTransferCommand
Here is that code:
Import-Module BitsTransfer
$password = ConvertTo-SecureString 'MyPassword' -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ("MyUserName", $password)
$MyFile = @("FIle.zip")
$url = "https://MyWebSite.com/" + $MyFile
$output = $PSScriptRoot + $MyFIle
Start-BitsTransfer -Authentication Basic -Credential $Cred -DisplayName "ThirdParty Files" -Source $url -Destination $output
Thursday, July 11, 2019 9:13 PM
PsCredential is only for authentication in Windows domains or to servers that support standard authentication types. It is not intended for authentication to web sites that may have complex multi-factor authentication.
First try removing "-Authentication" and let the service and the server negotiate the type.
\(ツ)_/
Ahh ok that makes since. So removing the -Authentication:
Start-BitsTransfer -Credential $Cred -DisplayName "ThirdParty Files" -Source $url -Destination $output
same error
Thursday, July 11, 2019 9:32 PM | 1 vote
Then the site does not support authentication. Contact the site owner.
\(ツ)_/
Thursday, July 11, 2019 9:34 PM
Then the site does not support authentication. Contact the site owner.
\(ツ)_/
Ok, that would make sense. Thank you for your help.