Tuesday, November 29, 2011

Information Worker Event

Hi
I presented at IW CPT ...
it was great fun ...and hope to do it again soon....
for all that attended thanks for taking the time to attend .....  it is much appreciated...
here is my slide deck...
also here is the PowerShell script to move the users......

//**************************BEGIN CODE*************************************
param([string]$url = (Read-Host "Enter the Url of the Web Application: "), `

[string]$oldprovider = `(Read-Host "Enter the Old Provider Name (Example -> Domain\ or MembershipProvider:) "), `
[string]$newprovider = `(Read-Host "Enter the New Provider Name (Example -> Domain\ or i:0#.f
MembershipProvider
) "))
add-pssnapin microsoft.sharepoint.powershell -EA 0
# Get all of the users in a site
$users = get-spuser -web $url
# Set a conversion flag which will later be used to verify if you want to continue processing
$convert = $false
# Loop through each of the users in the site
foreach($user in $users)
{
# Create an array that will be used to split the user name from the domain/membership provider
$a=@()
$displayname = $user.DisplayName
$userlogin = $user.UserLogin
# Separate the user name from the domain/membership provider
if($userlogin.Contains(':'))
{
$a = $userlogin.split(":")
$username = $a[1]
}
elseif($userlogin.Contains('\'))
{
$a = $userlogin.split("\")
$username = $a[1]
}
# Create the new username based on the given input
$newalias = $newprovider + $username
if (-not $convert)
{
$answer = Read-Host "Your first user will be changed from $userlogin to $newalias. Would you like to continue processing all users? [Y]es, [N]o"
switch ($answer)
{
"Y" {$convert = $true}
"y" {$convert = $true}
default {exit}
}
}
if(($userlogin -like "$oldprovider*") -and $convert)
{
move-spuser -identity $user -newalias "$newalias" -ignoresid -Confirm:$false
}
}
//**************************END CODE*************************************

2 comments:

  1. Thanks for this great article Bradly.

    One quick question, I tried to run this on my development environment and I get the following error message:

    Missing expression after ','.
    At c:\scriptname.ps1 :2 char:75
    + param([string]$url = (Read-Host "Enter the URL of the Web Application: "), <<
    << '
    + CategoryInfo : ParserError: (,:OperatorToken) [], ParseException
    + FullyQualifiedErrorId : MissingExpressionAfterToken


    Do i have to edit something on this script?

    Thanks,
    Sepaka

    ReplyDelete
  2. hi Sepaka
    i would suggest copy the script to notepad and then replace all the ' with ' ...as sometimes the format of these isnt recognised .... please reply with feedback and i might need to forward you the script.

    ReplyDelete