New-SPSite error – The system cannot find the file specified

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 :

  • URL
  • 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)…

*hhhhmmmm*

RESOLUTION :

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.

*phew*

Thankfully, that’s ALL it was !

🙂

Advertisements

One thought on “New-SPSite error – The system cannot find the file specified

  1. Really? I have this same issue, and I’ve found the only solution is to reboot the server. Of course, it only works for a while, then I start getting the error again.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s