Forum Discussion
Brent Ellis
Mar 13, 2017Silver Contributor
PnP PowerShell - tell if an Add-PnPFile was successful
What is the best way in powershell scripts to tell if an Add-PnPFile was actually successful in performing an upload? Ideally want to store a "successful" true or false in a variable.
Gary Schultz
May 04, 2018Iron Contributor
The following works for me
$FileSuccessLog = "C:\temp\logging\FileSuccessLog.log"
$FileFailureLog = "C:\temp\logging\FileFailureLog.log"
Try{
Add-PNPFile -Path $FilePath -folder "Some Document Library/Folder"
$fileSuccess = "Y"
}
Catch{
$fileSuccess = "N"
}
Finally {
Switch($fileSuccess){
N{
Add-content $FileFailureLog -value "$(get-date -f o) Failure with attempt to add file $FilePath."
}
Y{
Add-content $FileSuccessLog -value "$(get-date -f o) Success with attempt to add file $FilePath."
}
}
}