Skip to main content
replaced http://sharepoint.stackexchange.com/ with https://sharepoint.stackexchange.com/
Source Link

I am writing a PowerShell script to re-sync my users to the AD because of a problem I have described HereHere. From time to time I get a "Set-SPUser : user cannot be found." error but when I call the same command again with the same parameters no error appears and it simply works.

I have no problem just writing this line twice so if the error occurs, it'll simply work the second time it is called or even running the script twice in a row. But I prefer to understand this problem.

The code looks like this:

$allSiteCollections = Get-SPWebApplication [Web-Application-Name]

foreach ($siteCollection in $allSiteCollections.Sites)
{
    $currentWeb = Get-SPWeb $siteCollection.url

    $members = $currentWeb.SiteGroups["Members"]

    foreach ($currentUser in $members.Users)
    {
        Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"
    }
}

This is the line that throws the error:

Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"

If it throws the error and I re-run it, it works perfectly the second time.

Does anybody have any idea why does this happen?

I am writing a PowerShell script to re-sync my users to the AD because of a problem I have described Here. From time to time I get a "Set-SPUser : user cannot be found." error but when I call the same command again with the same parameters no error appears and it simply works.

I have no problem just writing this line twice so if the error occurs, it'll simply work the second time it is called or even running the script twice in a row. But I prefer to understand this problem.

The code looks like this:

$allSiteCollections = Get-SPWebApplication [Web-Application-Name]

foreach ($siteCollection in $allSiteCollections.Sites)
{
    $currentWeb = Get-SPWeb $siteCollection.url

    $members = $currentWeb.SiteGroups["Members"]

    foreach ($currentUser in $members.Users)
    {
        Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"
    }
}

This is the line that throws the error:

Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"

If it throws the error and I re-run it, it works perfectly the second time.

Does anybody have any idea why does this happen?

I am writing a PowerShell script to re-sync my users to the AD because of a problem I have described Here. From time to time I get a "Set-SPUser : user cannot be found." error but when I call the same command again with the same parameters no error appears and it simply works.

I have no problem just writing this line twice so if the error occurs, it'll simply work the second time it is called or even running the script twice in a row. But I prefer to understand this problem.

The code looks like this:

$allSiteCollections = Get-SPWebApplication [Web-Application-Name]

foreach ($siteCollection in $allSiteCollections.Sites)
{
    $currentWeb = Get-SPWeb $siteCollection.url

    $members = $currentWeb.SiteGroups["Members"]

    foreach ($currentUser in $members.Users)
    {
        Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"
    }
}

This is the line that throws the error:

Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"

If it throws the error and I re-run it, it works perfectly the second time.

Does anybody have any idea why does this happen?

Getting a "User cannot be found." error in Powershell even though i'm getting the users straight from the site collection itself

I am writing a PowerShell script to re-sync my users to the AD because of a problem iI have described Here and from. From time to time iI get a "Set-SPUser : user cannot be found." error but when iI call the same command again with the same parameters no error appears and it simply works. I

I have no problem just writing this line twice so if the error occurs, it'll simply work the second time it is called or even running the script twice in a row but i. But I prefer to understand this problem.

theThe code looks like this:

$allSiteCollections = Get-SPWebApplication [Web-Application-Name]

foreach ($siteCollection in $allSiteCollections.Sites)
{
    $currentWeb = Get-SPWeb $siteCollection.url

    $members = $currentWeb.SiteGroups["Members"]

    foreach ($currentUser in $members.Users)
    {
        Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"
    }
}

This is the line that throws the error:

Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"

If it throws the error and iI re-run it, it works perfectly the second time.

Does anybody have any idea why does this happen?

Thanks in advance, Itay.

Getting a "User cannot be found." error in Powershell even though i'm getting the users straight from the site collection itself

I am writing a PowerShell script to re-sync my users to the AD because of a problem i have described Here and from time to time i get a "Set-SPUser : user cannot be found." error but when i call the same command again with the same parameters no error appears and it simply works. I have no problem just writing this line twice so if the error occurs it'll simply work the second time it is called or even running the script twice in a row but i prefer to understand this problem.

the code looks like this:

$allSiteCollections = Get-SPWebApplication [Web-Application-Name]

foreach ($siteCollection in $allSiteCollections.Sites)
{
    $currentWeb = Get-SPWeb $siteCollection.url

    $members = $currentWeb.SiteGroups["Members"]

    foreach ($currentUser in $members.Users)
    {
        Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"
    }
}

This is the line that throws the error:

Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"

If it throws the error and i re-run it, it works perfectly the second time.

Does anybody have any idea why does this happen?

Thanks in advance, Itay.

"User cannot be found." error in Powershell

I am writing a PowerShell script to re-sync my users to the AD because of a problem I have described Here. From time to time I get a "Set-SPUser : user cannot be found." error but when I call the same command again with the same parameters no error appears and it simply works.

I have no problem just writing this line twice so if the error occurs, it'll simply work the second time it is called or even running the script twice in a row. But I prefer to understand this problem.

The code looks like this:

$allSiteCollections = Get-SPWebApplication [Web-Application-Name]

foreach ($siteCollection in $allSiteCollections.Sites)
{
    $currentWeb = Get-SPWeb $siteCollection.url

    $members = $currentWeb.SiteGroups["Members"]

    foreach ($currentUser in $members.Users)
    {
        Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"
    }
}

This is the line that throws the error:

Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"

If it throws the error and I re-run it, it works perfectly the second time.

Does anybody have any idea why does this happen?

Tweeted twitter.com/#!/StackSharePoint/status/330819384748687361
added 52 characters in body
Source Link

I am writing a PowerShell script to syncre-sync my users to the AD because of a problem i have described Here and from time to time i get a "Set-SPUser : user cannot be found." error but when i call the same command again with the same parameters no error appears and it simply workworks. I have no problem just writing this line twice so if the error occurs it'll simply work the second time it is called or even running the script twice in a row but i prefer to understanunderstand this problem.

the code looks like this:

$allSiteCollections = Get-SPWebApplication [Web-Application-Name]

foreach ($siteCollection in $allSiteCollections.Sites)
{
    $currentWeb = Get-SPWeb $siteCollection.url

    $members = $currentWeb.SiteGroups["Members"]

    foreach ($currentUser in $members.Users)
    {
        Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"
    }
}

If i writeThis is the line that throws the error:

Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"

TwiceIf it throws the error and i re-run it, it works perfectly the second time.

Does anybody have any idea why does this happen?

Thanks in advance, Itay.

I am writing a PowerShell script to sync my users to the AD because of a problem i have described Here and from time to time i get a "Set-SPUser : user cannot be found." error but when i call the same command again with the same parameters no error appears and it simply work. I have no problem just writing this line twice so if the error occurs it'll simply work the second time it is called or even running the script twice in a row but i prefer to understan this problem.

the code looks like this:

$allSiteCollections = Get-SPWebApplication [Web-Application-Name]

foreach ($siteCollection in $allSiteCollections.Sites)
{
    $currentWeb = Get-SPWeb $siteCollection.url

    $members = $currentWeb.SiteGroups["Members"]

    foreach ($currentUser in $members.Users)
    {
        Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"
    }
}

If i write the line that throws the error:

Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"

Twice it works perfectly.

Does anybody have any idea why does this happen?

Thanks in advance, Itay.

I am writing a PowerShell script to re-sync my users to the AD because of a problem i have described Here and from time to time i get a "Set-SPUser : user cannot be found." error but when i call the same command again with the same parameters no error appears and it simply works. I have no problem just writing this line twice so if the error occurs it'll simply work the second time it is called or even running the script twice in a row but i prefer to understand this problem.

the code looks like this:

$allSiteCollections = Get-SPWebApplication [Web-Application-Name]

foreach ($siteCollection in $allSiteCollections.Sites)
{
    $currentWeb = Get-SPWeb $siteCollection.url

    $members = $currentWeb.SiteGroups["Members"]

    foreach ($currentUser in $members.Users)
    {
        Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"
    }
}

This is the line that throws the error:

Set-SPUser -Identity $currentUser.UserLogin -Web $currentWeb.url -SyncFromAD -Group "Members"

If it throws the error and i re-run it, it works perfectly the second time.

Does anybody have any idea why does this happen?

Thanks in advance, Itay.

edited title
Link
Loading
Source Link
Loading