3

I wish to go through a sharepoint list and if a property (a choice field named Status) is a certain value then change the author of that item.

Add-PSSnapin Microsoft.SharePoint.Powershell
$web = Get-SPWeb "http://site"
$library = $web.Lists["UserInfo"]
$newUser = $web.EnsureUser("user1")
$oldUser = $web.EnsureUser("user2")

foreach ($item in $library.Items)
{
   #$userfield = New-Object Microsoft.SharePoint.SPFieldUserValue($web,$item["DocumentAuthorColumnInternalName"].ToString())
   $userfield = New-Object Microsoft.SharePoint.SPFieldUserValue($web,$item["Author"].ToString())
   $userfield = New-Object Microsoft.SharePoint.SPFieldUserValue($web,$item["Author"].ToString())
   $login = $userfield.User.LoginName
   #if ($login -eq $oldUser.LoginName)
   if ($login -eq $oldUser.LoginName)
   {

#if($item["Status"] eq 'Fully Implemented')
#{
    $item["Author"] = $newUser
        #if you are using default "Author" column, you need to set the following as well:
        $item.Properties["vti_author"] = $newUser.LoginName
        $item.UpdateOverwriteVersion() #this saves changes without incrementing the version
       #}
   }
   $login = $null
}

$web.Dispose();

I can get it working but when I reach the line

if($item["Status"] eq 'Fully Implemented')

It causes an error

unexpected token 'eq'

1
  • 1
    -eq, not eq Commented May 31, 2019 at 12:57

1 Answer 1

3

Have you just missed the hyphen in eq? So it should be:

if($item["Status"] -eq 'Fully Implemented')
{
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.