Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于列出组成员身份的Powershell脚本_Powershell - Fatal编程技术网

用于列出组成员身份的Powershell脚本

用于列出组成员身份的Powershell脚本,powershell,Powershell,我编写了以下脚本,列出了contractorsemployeetype=contractors的所有用户,这些用户不是特定组(如域contractors)的一部分,但它不起作用,有人能帮忙吗: $adusers = get-aduser -filter * -searchbase "OU=test,dc=domain,dc=com" -properties employeetype | where {($_.employeetype -like "contractor") -AND ($_.en

我编写了以下脚本,列出了contractorsemployeetype=contractors的所有用户,这些用户不是特定组(如域contractors)的一部分,但它不起作用,有人能帮忙吗:

$adusers = get-aduser -filter * -searchbase "OU=test,dc=domain,dc=com" -properties employeetype | where {($_.employeetype -like "contractor") -AND ($_.enabled -eq $true)} 
foreach ($aduser in $adusers){ 
    $contractorsDn = (Get-ADGroup 'domaincontractors').DistinguishedName 
    Get-ADUser $aduser -LDAPFilter "(!(memberof=$contractorsDn))"
}

$users=get aduser-filter{employeetype-like contractor-AND enabled-eq$true}-searchbase dc=domain,dc=COM-properties employeetype $group=域名承包商

$members=Get-ADGroupMember-Identity$group-Recursive | Select-ExpandProperty DifferentizedName

ForEach$user在$users中{

If ($members -contains $user) {
  write-host "$user exists" -ForegroundColor Red
}否则{ 写入主机$user不存在-ForegroundColor绿色
}}

$aduser=get aduser-filter*-searchbase OU=test,dc=domain,dc=com-properties-employeetype |其中{$$\.employeetype-like contractor-和$\.enabled-eq$true}foreach$aduser中的$aduser{$contractorsDn=get ADGroup'domaincontractors'。区分名称get aduser$aduser-LDAPFilter!memberof=$contractorsDn}请编辑您的问题,以包括您尝试的代码以及任何错误消息。不要将您的代码放在注释中,而是将其放在问题中,并使用{}标记。我已将代码添加到问题中,但问题仍然是您没有解释错在哪里?发生了什么事?你期待什么?嘿,马特,谢谢你编辑这个问题。我正在尝试列出所有不属于该组的承包商,而不是我得到所有承包商的名单