SharePoint 2010声明了经典的PowerShell帮助
-
09-12-2019 - |
题
我有客户要求从经典转移到索赔。我目前正在利用 http://derekmartin.org/archives/701
$webApp =
$farm = get-SPFarm
$wa = get-SPWebApplication $webApp
$site = get-SPSite $webApp
$web = $site.OpenWeb()
foreach ($user in $web.AllUsers) {
$newuser = $user
$newuserLoginName = “”
write-host($user.LoginName)
if ($newuser.LoginName.StartsWith(“i:0#.w|”))
{
! $newuserLoginName = $user.LoginName.Substring(7)
}
$user = $newuser
$farm.MigrateUserAccount($user.LoginName, $newuserLoginName, $false)
}
.
不幸的是每次我尝试运行它时,我都会得到以下
无效的赋值表达式。赋值运算符的左侧需要是可以分配的东西 喜欢变量或属性。 在C:\ Users \ User \ Desktop \ \ ops.ps1:12字符:22 +$ newuserloginname= <<<< $ user.loginname.substring(7) + categinyfo:parserError:(:) [],ParseException +全新rifiedErrorid:InvalideLefthandside
对可能是错误的想法?
谢谢! 抱歉忘了原来粘贴脚本!
解决方案
I may be wrong but I suppose that the exclamation mark on the
!$newuserLoginName = $user.LoginName.Substring(7)
line should just be a refuse (or at last it doesn't match any syntax I am aware of).
If you are on a test environment or are otherwise sure that you won't damage your system with a wrong comand, I would try to replace the if with:
if ($newuser.LoginName.StartsWith(“i:0#.w|”))
{
$newuserLoginName = $user.LoginName.Substring(7)
}
The if should simply remove the "claim specific part" from the login name, so I would assume the original blog post intended it this way.
That said, know that I have never done this before and are only trying to spot an error in the powershell code. I don't know if that code will actually do what promised, so use that at your risk (or wait some more expert other user to confirm the behaviour).