SOLVED

recycling the deleted site from recycle bin

%3CLINGO-SUB%20id%3D%22lingo-sub-92485%22%20slang%3D%22en-US%22%3Erecycling%20the%20deleted%20site%20from%20recycle%20bin%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-92485%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20put%20together%20a%20script%20to%20delete%20a%20site%20collection%20from%20te%20recycle%20bin%20of%20office%20365%20Admin%20SharePoint%3C%2FP%3E%3CP%3EIt%20executes%20fine%20however%20it%20starts%20with%20an%20exception%20with%20%22.ctor%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24siteAdminURL%20%3D%20%22https%3A%2F%2F%26lt%3Bmydomain%26gt%3B-admin.sharepoint.com%22%0AImport-Module%20Microsoft.Online.SharePoint.PowerShell%20%E2%80%93DisableNameChecking%0A%24Credentials%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24cred.Username%2C%24cred.Password)%0AConnect-SPOService%20-Url%20%24siteAdminUrl%20-Credential%20%24Credentials%0A%20%0A%20%24siteurl%20%3D%20read-host%20%22enter%20the%20site%20collection%20URL%22%0A%20Remove-SPODeletedSite%20%E2%80%93Identity%20%24siteurl%20%E2%80%93Confirm%3A%24false%3C%2FPRE%3E%3CP%3EIs%20there%20any%20change%20required.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-92523%22%20slang%3D%22en-US%22%3ERe%3A%20recycling%20the%20deleted%20site%20from%20recycle%20bin%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-92523%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20what%20you've%20listed%20the%20full%20script%3F%20If%20so%20I%20think%20the%20error%20results%20from%20the%20way%20you%20use%20%24Credentials.%20There's%20no%20%24cred%20variable%20in%20the%20script.%20Besides%2C%20as%20far%20as%20I%20know%20Connect-SPOService%20doesn't%20accept%20an%20object%20of%20type%20SharePointOnlineCredentials%20to%20be%20passed%20as%20an%20argument.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20modified%20script%20below%20works%20for%20me%20without%20any%20error%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24cred%20%3D%20Get-Credential%0A%24siteAdminURL%20%3D%20%22https%3A%2F%2F%26lt%3Bmydomain%26gt%3B-admin.sharepoint.com%22%0AImport-Module%20Microsoft.Online.SharePoint.PowerShell%20%E2%80%93DisableNameChecking%0A%0AConnect-SPOService%20-Url%20%24siteAdminUrl%20-Credential%20%24cred%0A%20%0A%20%24siteurl%20%3D%20read-host%20%22enter%20the%20site%20collection%20URL%22%0A%20Remove-SPODeletedSite%20%E2%80%93Identity%20%24siteurl%20%E2%80%93Confirm%3A%24false%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Highlighted
Regular Contributor

I have put together a script to delete a site collection from te recycle bin of office 365 Admin SharePoint

It executes fine however it starts with an exception with ".ctor".

 

$siteAdminURL = "https://<mydomain>-admin.sharepoint.com"
Import-Module Microsoft.Online.SharePoint.PowerShell –DisableNameChecking
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.Username,$cred.Password)
Connect-SPOService -Url $siteAdminUrl -Credential $Credentials
 
 $siteurl = read-host "enter the site collection URL"
 Remove-SPODeletedSite –Identity $siteurl –Confirm:$false

Is there any change required.

1 Reply
Highlighted
Best Response confirmed by null null (Regular Contributor)
Solution

Is what you've listed the full script? If so I think the error results from the way you use $Credentials. There's no $cred variable in the script. Besides, as far as I know Connect-SPOService doesn't accept an object of type SharePointOnlineCredentials to be passed as an argument.

 

The modified script below works for me without any error

 

$cred = Get-Credential
$siteAdminURL = "https://<mydomain>-admin.sharepoint.com"
Import-Module Microsoft.Online.SharePoint.PowerShell –DisableNameChecking

Connect-SPOService -Url $siteAdminUrl -Credential $cred
 
 $siteurl = read-host "enter the site collection URL"
 Remove-SPODeletedSite –Identity $siteurl –Confirm:$false