Our company creates a Workspace folder for each user that is owned by a central service account. I’m trying to build a script with Box CLI and PowerShell to delete a user’s Workspace folder after we delete their account to free up a license.
Every time I try to get the folder details or delete the folder, I’m greeted with a d_ prefix on the item and it can’t find the folder. If I try to just get the folder, folders:get still attempts to add a d_ prefix and folders:items is probably incorrect. I’m signed into CLI as our global admin account which owns this content, so it shouldn’t be a permissions problem. If I do a folders:items 0 as the given user, I see the workspace folder and ID.
The code imports a CSV of folders that I’ve pulled already. I’m still new to the CLI so obviously I’m doing something wrong but I don’t know why it’s adding a d_ prefix to the content. I’ve tried to add a Trim() to the folder ID, but the folder ID shows correct in the text output before the actual delete command.
The Collaborations line was when I was trying to run it as my own co-admin account. Commenting that out to ignore it still gives the invalid parameter error above.
try {
$Folders = Import-Csv $FolderList
Write-Log "Importing csv of folders to delete." -output true
}
catch {
Write-Log "Error reading folder data from CSV file $FolderList" -exception $_.Exception -output true -color Red
break
}
# Delete Folder
ForEach($Folder in $Folders) {
$folderID = $Folder.ID.Trim()
# Check if user exists and get user ID
Write-Output "Attempting to delete $($FolderID), $($Folder.name)"
try {
box folders:collaborations:add --folder-id $folderID --user-id $DeletionUser --role editor
box folders:delete $folderID --yes --as-user $DeletionUser
Write-Output "Deletion successful."
}
catch {
Write-Log "Skipping this folder. Could not delete $($Folder). See log for details." -output true -color Red
continue
}
}