Recently, I was using some PowerShell scripts to automate the creation of a bunch of Site Collections.
The script I have goes a little like this :
$template = Get-SPWebTemplate “STS#0”
write-host “Create SC /team/HR”
New-SPSite https://spr/team/HR -Name “Human Resources” -OwnerAlias “SPRfred” -SecondaryOwnerAlias “SPRbrenda” -ContentDatabase SPR_SQL_TEAMS01 -QuotaTemplate LargeSiteCollection -Language 1033 -template $template
To break this apart – the parameters are :
- Name = Display Name of the Site Collection
- Owner + Secondary Owner = Site Collection Admins
- ContentDatabase = which SQL DB to use
- QuotaTemplate = define a sizing to the Site Collection
- Language – to use English (1033)
- Template = sourced from the STS#0 template (Team Site)
But – I’m getting an error – which is kinda strange – and resulting in some log-looking…
EVENT LOG :
The site /team/HR could not be created.
The following exception occurred: The system cannot find the file specified. (Exception from HRESULT: 0x80070002).
I re-tried the script – and removed the “-template” parameter – AND – it worked !
When I loaded up the Site Collection – I was prompted to select the Site Collection Template (/_layouts/templatepick.aspx)…
When executing the PowerShell command, I was logged in as a Farm Admin – so I have plenty of permissions (god-mode).
HOWEVER – the PowerShell session does not have access to the local File System – and thus cannot read the files (ONET.XML) for the Site Template – aaaahhhaaa !!
The simple answer (facepalm !) is to RUN AS ADMIN when opening the PowerShell command window.
Thankfully, that’s ALL it was !