Скрипт экспортируется в CSV, и файлы необходимо загрузить в SharePoint онлайн.
- Экспорт работает отлично
- Документ переименован, чтобы исключить "@ mycompany.com"
- Я получаю следующую ошибку:
Исключение, вызывающее «ExecuteQuery» с аргументом (ами) «0»: «Удаленный сервер возвратил ошибку: (403) Запрещено». В строке: 46 символов: 9 + $ Context.ExecuteQuery () + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId: WebException
Get-ChildItem 'c:\users\xxxx\downloads' -Filter *.csv | % {
$eachFile =Get-ChildItem $Outputfile -Filter *.csv
$eachFile | ForEach-Object{
#Upload Variables - Admin Heidi
[string]$AdminName = "hxxn@xxx.onmicrosoft.com"
[string]$AdminPassword = "Cxx1"
#Upload Credentials
[SecureString]$SecurePass = ConvertTo-SecureString $AdminPassword -AsPlainText -Force
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $AdminName, $(convertto-securestring $AdminPassword -asplaintext -force)
$AdminSiteURL="https://nrcl.sharepoint.com"
#Site report will be stored on SharePoint
$SiteURL="https://xxx.sharepoint.com/sites/nrg/"
$LibraryName="Audit History"
#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Context.Credentials = $Credentials
#Get the Library
$Library = $Context.Web.Lists.GetByTitle($LibraryName)
#Get the file from c:/
$FileStream = ([System.IO.FileInfo] (Get-Item $OutputFile)).OpenRead()
#Get File Name from source file path
$SourceFileName = Split-path $eachFile -leaf
#sharepoint online upload file powershell
$FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$FileCreationInfo.Overwrite = $true
$FileCreationInfo.ContentStream = $FileStream
$FileCreationInfo.URL = $SourceFileName
$FileUploaded = $Library.RootFolder.Files.Add($FileCreationInfo)
#powershell upload single file to sharepoint online
$Context.Load($FileUploaded)
#######--------fails after this line ---------------#####
$Context.ExecuteQuery()
#Close file stream
$FileStream.Close()
write-host "File has been uploaded!"
}