New-SPSite : User cannot be found
I recently had a bit of a head-scratcher with a "User cannot be found" error when using PowerShell to create a site collection in SharePoint Server 2010. My command was quite simple:
New-SPSite -url http://servername/sites/site -owneralias "domain\username" -template "STS#0" -Name "Site Title Here"
I received an error "User cannot be found"
If I removed the "domain\" the command worked every time:
New-SPSite -url http://servername/sites/site -owneralias "username" -template "STS#0" -Name "Site Title Here"
I hope this helps someone else who runs into this issue.
New-SPSite -url http://servername/sites/site -owneralias "domain\username" -template "STS#0" -Name "Site Title Here"
I received an error "User cannot be found"
If I removed the "domain\" the command worked every time:
New-SPSite -url http://servername/sites/site -owneralias "username" -template "STS#0" -Name "Site Title Here"
I hope this helps someone else who runs into this issue.
Comments
New-SPSite ... -OwnerAlias "administrator"
In fact, after this line being run, the owner might be a local account (in case a local account has the same name as its domain counterpart):
(Get-SPSite -Identity http://...site...coll..).Owner.UserLogin
Here is shown the local account, right?
New-SPSite ... -OwnerAlias "administrator"
In fact, after this line being run, the owner might be a local account (in case a local account has the same name as its domain counterpart):
(Get-SPSite -Identity http://...site...coll..).Owner.UserLogin
Here is shown the local account, right?
The solution for me was to make a variable for the Userdomain, and use the variable in front of the username, instead of writing the domainname directly.
This is how my script looks like now. It will read the sitenames from a txt file named sites.txt.
$Userdomain = gc env:UserDomain
$sites = Get-Content .\sites.txt
$owner = "$userdomain\user1"
$secowner = "$userdomain\user2"
$template = "STS#0"
$environment = "http://sharepoint/sites/"
foreach ($site in $sites) {
new-spsite -url $environment$site -owneralias $owner -secondaryowneralias $secowner -template $template -name $site
write-host "$environment$site has been created"
}