【问题标题】:Must provide a value expression on the right-hand side of the '-' operator必须在“-”运算符的右侧提供值表达式
【发布时间】:2017-11-19 18:28:20
【问题描述】:
$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 ';'}}
}

您好...当我在服务器 2008 中运行上述脚本时,我收到下面提到的错误。

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 ';'}}

您能帮我找出问题所在吗?

【问题讨论】:

  • 错误消息中的格式看起来有点奇怪...你是从某个地方复制的吗?看起来里面有一个奇怪的字符...
  • 是的,我拿这个来做个例子试试……
  • 也刚刚发现该错误仅出现在powershell v1.0中,但在其他版本中它很好...请告诉我您是否可以帮助我...

标签: powershell powershell-2.0 windows-server-2008 powershell-1.0


【解决方案1】:

这看起来有点像,其他人postet。如果 Powershel 1 不支持-join(我真的不知道,但我看起来像),你可以这样做:

$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)}}
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多