Forum Discussion

null null's avatar
null null
Iron Contributor
Aug 02, 2017

recycling the deleted site from recycle bin

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.

  • 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
  • paulpascha's avatar
    paulpascha
    Bronze Contributor

    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

Resources