Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when checking array element in Powershell script : unexpected token 'eq'

Tags:

powershell

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'

like image 473
Pete Whelan Avatar asked Jan 26 '26 02:01

Pete Whelan


1 Answers

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

if($item["Status"] -eq 'Fully Implemented')
{
}
like image 102
I.T Delinquent Avatar answered Jan 28 '26 21:01

I.T Delinquent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!