Archive for the 'PowerShell' Category

31
Dec
15

PowerShell to Add FBA User to SharePoint Group and EnsureUser

function global:Add-FBAMember([parameter(mandatory=$true)][string]$siteCollUrl, [parameter(mandatory=$true)][string]$fbaUser, [parameter(mandatory=$true)][string]$spGroup)

{

# Created by Russell Wright 2015-12-21

# Updated by Russell Wright 2015-12-31 Added AllowUnsafeUpdates

# Must have machine.config <membership>, <roleManager> and <connectionStrings> sections

Add-PSSnapin microsoft.sharepoint.powershell

$web = Get-SPWeb -identity $siteCollUrl

# Save the value of AllowUnsafeUpdates

$allowUnsafeUpdates = $web.AllowUnsafeUpdates

$web.AllowUnsafeUpdates = $true

# EnsureUser initializes the user in SharePoint

$user = $web.EnsureUser($fbaUser)

$getuser = Get-SPUser -Identity $user -Web $siteCollUrl

# Set-SPUser adds the user to the SharePoint group

Set-SPUser -Identity $user -Web $siteCollUrl -Group $spGroup

$web.AllowUnsafeUpdates=$allowUnsafeUpdate

$retMsg = "Added user: " + $fbaUser + " to group " + $spGroup + " in " + $siteCollUrl

$retMsg

}

We needed a PowerShell Function to call from Winshuttle Workflow that would ensure the user was in SharePoint after a SQL load to the aspnetdb.  The trick appears to be using "AllowUnsafeUpdates," similar to what many others have posted with their C# code.  There were also some items noted in the config files where the machine.config required the FBA connection string in order for the PowerShell to work.

29
May
14

Remove-SPUser PowerShell Command: How to Use it in SharePoint 2013

I was trying to use the Remove-SPUser cmdlet and kept getting this error:

Remove-SPUser : You must specify a valid user object or user identity.

image

With claims based authentication the cmdlet Get-SPUser returns all users like this:

image

So, you can see the format of the –Identity (UserLogin) is something like this:

i:0#.w|DOMAIN\USERID

This thread referred to the Get-SPUser cmdlet and using New-SPClaimsPrincipal, but what I found was pretty simple.

http://social.msdn.microsoft.com/Forums/en-US/260ad45b-cfe7-4699-842b-fc2ecdf6e543/powershell-cant-getspuser-adfs-user?forum=sharepointgeneralprevious

Use this format for the cmdlet:

Remove-SPUser -identity "i:0#.w|cfgmgt\rwright" -web http://cmsp2013:5555

The trick for me was to put double quotes around the encoded user name.

Now, if the Microsoft documentation would be more accurate…




Asif Rehmani’s SharePoint Videos

SharePoint-Videos

Click to access a wealth of SharePoint videos

SharePoint Rx

SharePoint Rx Home

Categories

Posts by Date

December 2019
M T W T F S S
« Jun    
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
Support Wikipedia