Create and Delete Site Collection from .CSV File using PowerShell Script

  1. #********** Create multiple  Site Collections from .csv file *********************************************  
  2. #csv file path  
  3. $csvfile = 'C:\doc\CreateSiteCollections.csv'  
  4. #O-365 site url and Credential   
  5. Connect-SPOService -Url https://ajay-admin.sharepoint.com -Credential [email protected]  
  6.   
  7. Import-Csv $csvfile |   
  8.     where {  
  9.     Write-Host "Creating Site Collection: " $_.URL  
  10.         New-SPOSite -Owner $_.Owner -StorageQuota $_.StorageQuota -Url $_.URL -NoWait -ResourceQuota $_.ResourceQuota -Template $_.Template -TimeZoneID $_.TimeZoneID -Title $_.Title -LocaleID $_.Language    
  11.     }  
  12.  
  13.  
  14.  
  15.  
  16. #********** delete multiple Site Collections from .csv file *********************************************  
  17. $csvfile = 'C:\doc\DeleteSiteCollections.csv'  
  18. Connect-SPOService -Url https://ajay-admin.sharepoint.com -Credential [email protected]  
  19.   
  20. Import-Csv $csvfile |   
  21.     where { Write-Host "Deleting "$_.URL           
  22.   
  23.         remove-sposite –identity $_.URL -Confirm:$False  
  24.         Write-Host "Moved to recycle bin"  
  25.         remove-spodeletedsite –identity $_.URL -Confirm:$False  
  26.         Write-Host "Removed from recycle bin"  
  27.           }  

Owner StorageQuota Url ResourceQuota Template TimeZoneID Title Language
[email protected] 20480 https://xyz.sharepoint.com/sites/admin 300 STS#0 4 Admin 1033
 
Delete site collection pass only site collection Url column