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

when I run the above mentioned script in server 2008, I am not getting output with the local user name…pls let me know if you can assist me in that…But its working fine in 2008R2 and also in 2012.

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

The last line of your code seems not be connected to the rest of the script. You are using $_ outside a pipeline. To get the local user names you could simply your script using:

$adsi = [ADSI]"WinNT://$env:COMPUTERNAME" 
$adsi.Children | Where-Object {$_.SchemaClassName -eq 'user'} | ForEach-Object {

Thanks for your reply Dirk. I tried that

$adsi = [ADSI]"WinNT://$env:COMPUTERNAME" $adsi.Children | Where-Object {$_.SchemaClassName -eq 'user'} | ForEach-Object {$_.Name} 

I am getting error

Unexpected token 'adsi' in expression or statement.
At line:1 char:48
+ $adsi = [ADSI]"WinNT://$env:COMPUTERNAME" $adsi. <<<< Children | Where-Object {$_.SchemaClassName -eq 'user'} | ForEach-Object {$_.Name} 

Anything I can change in that script, pls let me know…

I also tried this mentioned below -

$adsi = ([ADSI]"WinNT://$env:COMPUTERNAME").Children | Where-Object {$_.SchemaClassName -eq 'user'} | ForEach-Object {$_.Name}

I dont see any output…

It appears, that you have copied and pasted the code into the console instead of running it from ISE. If you do that you should add semicolons:

#ugly "one" liner
$adsi = [ADSI]"WinNT://$env:COMPUTERNAME";$adsi.Children | Where-Object {$_.SchemaClassName -eq 'user'} | ForEach-Object {$_.Name} 

Do yourself a favor and use the PowerShell Module to Manage Local Users and Groups :wink: :smiley:

Thanks Dirk. I used the script that you mentioned as well and not getting any output. any advice, pls let me know…

@ Olaf Soyk, :slight_smile: Yes, I understand what you mean, but we have few servers with version 1.0. Thats why I am trying to find a solution. Hope you can assist as well…

Try it piece by piece. Do you see any output?:


Do you see output that has SchemaClassName “User”, when you run this one?:

([ADSI]"WinNT://$env:COMPUTERNAME").Children | select SchemaClassName

What is it actually what you’re trying to do with this code?

Hi Dirk, I only see output as mentioned below -

 PS C:\Temp> ([ADSI]"WinNT://$env:COMPUTERNAME")


PS C:\Temp> ([ADSI]"WinNT://$env:COMPUTERNAME").Children | select SchemaClassName

Hi Olaf Soyk, I am trying to get the local users from server that has powershell v1.0 using the ADSI.

But I came to know that v1.0 didn’t implement an [ADSI] accelerator…which makes sense…

Seems that ADSI doesn’t work on v1. You could use WMI instead:

Get-WmiObject -Class Win32_UserAccount

Thanks Dirk…