Hello All,
I am trying to pull an excel file from the Microsoft Team share path using the below PowerShell script but have encountered an error,
$SharePoint = “https://xyz.sharepoint.com/:x:/r/sites/xyz/Shared%20Documents/General/tool/Test-API.xlsx”
$Path = “C:\tool\Test-API.xlsx”
#Get User Information
$username = “xyz@decom.com”
$password = Read-Host “Enter your password” -AsSecureString
#Download Files
$WebClient = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.Networkcredential($UserName, $Password)
$WebClient.DownloadFile($SharePoint, $Path)
Error encountered
Exception calling “DownloadFile” with “2” argument(s): “The remote server returned an error: (401) Unauthorized.”
At line:11 char:1
- $WebClient.DownloadFile($SharePoint, $Path)
-
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException
Please suggest