Get-PnPFolder - Confirm folder exists in all OneDrive locations specified in a CSV #1894
Unanswered
Macattack99
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm hoping there's a way to get the following code working efficiently. It works for the first row in the CSV but then only randomly does it succeed but for all the ones that show up as "Folder does not exist" I've confirmed the folder does actually exist.
Sample Input from CSV;
ONEDRIVEURL
https://-my.sharepoint.com/personal//
Sample output;
Folder exists!
row @{ONEDRIVEURL=https://-my.sharepoint.com/personal//}
row.onedriveurl https://-my.sharepoint.com/personal//
Folder URL Documents/_H_Drive_Copy
Site URL https://-my.sharepoint.com/personal//
Folder Microsoft.SharePoint.Client.Folder
$csvFile = "C:\temp\OneDrive\checkup.csv" $table = Import-Csv $csvFile $connection=Connect-PnPOnline -Url "https://<inserttenat>-admin.sharepoint.com/" -Interactive Set-Variable SiteURL, FolderURL, Folder $FolderURL = "Documents/_H_Drive_Copy" foreach ($row in $table) { Clear-Variable SiteURL Clear-Variable Folder $SiteURL = $row.ONEDRIVEURL #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -interactive #Try to Get the Folder $Folder = Get-PnPFolder -Url $FolderURL -ErrorAction SilentlyContinue #sharepoint online powershell To check if folder exists If($Folder -ne $null) { Write-Host -f Green "Folder exists!" } Else { Write-Host -f Yellow "Folder does not exists!" for $SiteURL $row.ONEDRIVEURL >> c:\temp\OneDrive\missing_H.txt } ###For testing purposes### Write-Host "row" $row Write-Host "row.onedriveurl" $row.onedriveurl Write-Host "Folder URL" $FolderURL Write-Host "Site URL" $SiteURL Write-Host "Folder" $Folder }
Beta Was this translation helpful? Give feedback.
All reactions