PowerShell command to add all users via claims via PowerShell to SharePoint
New-spuser “c:0(.s|true" -web http://www.mysharepointsite.com/ -permissionlevel "read"
PowerShell command to add all users via claims via PowerShell to SharePoint
New-spuser “c:0(.s|true" -web http://www.mysharepointsite.com/ -permissionlevel "read"
I recently was given a WSP to add to our farm.
In this case after the WSP was installed and deployed we needed to activate the feature at the site collection level.
Thats usually easy enough to do through the UI, but in this particular case we had a web application which had over a dozen site collections.
ie:
Activating it at http://jack.com from the UI was fine, but when the user navigated to http://jack.com/blog they were stumbling onto another site collection, and the feature wasn’t activated there.
To activate it on every Site collection meant that I’d have to a) know what each site collection was, and b) visit that site, and activate the feature.
Too much work.
What was needed was a simple script that would loop though each site collection, enabling the feature on each one.
The script below is a result of that need…
# this script enables a feature on every site collection on a given web app
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$webs = get-spsite -webapplication "http://www.yoursharepointURL.com"
$feature = "YourFeatureName" #this might not be what you expect it to be, best to do get-spfeature | Select displayname
Foreach ($oneweb in $webs)
{
write-host $oneweb
$siteFeature = get-spfeature -site $oneweb | Where {$_.displayname -eq $feature}
if ($siteFeature -eq $null)
{
Write-Host "Activating Site level Features at $oneweb" -foregroundcolor Yellow
Enable-SPFeature -Identity $Feature -URL $oneweb.URL -Confirm:$False
}
else
{
Write-Host "Feature $feature is already activated on $oneweb" -foregroundcolor green
}
}
If you look at the simple logic, you’ll see you can run it more than once – and the second time you run it, it should display an all green list indicating that all the site collections already have the feature activated.
See who has them with
get-spshelladmin
add one with
add-spshelladmin
Add-SPShellAdmin Domain\Username #then do it again for all the content databases Get-SPContentDatabase | Add-SPShellAdmin Domain\Username