Must provide a value expression on the right-hand side of the '-' operator

716 views Asked by At
$adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
$adsi.Children | where {$_.SchemaClassName -eq 'user'} | Foreach-Object {
$groups = $_.Groups() | Foreach-Object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
$_ | Select-Object @{n='UserName';e={$_.Name}},@{n='Groups';e={$groups -join ';'}}
}

Hi there...when I run the above mentioned script in server 2008, I getting error mentioned below.

You must provide a value expression on the right-hand side of the '-' operator.
At C:\Temp\Usrgrp.ps1:4 char:73
+ $_ | Select-Object @{n='UserName';e={$_.Name}},@{n='Groups';e={$groups -j <<<< oin ';'}}

Can you pls assist me in finding out whats the issue ?

1

There are 1 answers

0
restless1987 On

This looks a bit like, what that other guy postet. If Powershel 1 does not support -join (I dont really know, but i looks like), you could go with that:

$adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
$adsi.Children | Where-Object {$_.SchemaClassName -eq 'user'} | Foreach-Object {
    $groups = $_.Groups() | Foreach-Object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
    $_ | Select-Object @{n='UserName';e={$_.Name}},@{n='Groups';e={[string]::(';',$groups)}}
}