以下是我目前尝试将AD管理组取名为“ML ...”等相同名称的尝试。我不断收到错误,所以我想知道为什么当我可以通过“-eq $ ...”变量过滤managedby时,我无法使用“-like”过滤managedby。我尝试了一个变量$ name =“ML *”,这样我就可以执行{managedby -eq $ name},但仍然没有运气。由Powershell管理的过滤器
我大多得到错误,如:
Operator(s): The following: ''Eq', 'Ne'' are the only operator(s) suppor
ted for searching on extended attribute: 'ManagedBy'.
等等,因为“当量”是只接受一些滤镜我已经做了。当我使用当量我得到这些错误:
Import-Module : The following error occurred while loading the extended type dat
a file:
Microsoft.PowerShell, C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\ActiveD
irectory\ActiveDirectory.Types.ps1xml : File skipped because it was already pres
ent from "Microsoft.PowerShell".
Microsoft.PowerShell, C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\ActiveD
irectory\ActiveDirectory.Types.ps1xml : File skipped because it was already pres
ent from "Microsoft.PowerShell".
At J:\\ManagedbyEqualsML.ps1:1 char:14
+ Import-Module <<<< ActiveDirectory
+ CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeExc
eption
+ FullyQualifiedErrorId : FormatXmlUpateException,Microsoft.PowerShell.Comm
ands.ImportModuleCommand
The term 'Get-adgroup' is not recognized as the name of a cmdlet, function, scri
pt file, or operable program. Check the spelling of the name, or if a path was i
ncluded, verify that the path is correct and try again.
At J:\\ManagedbyEqualsML.ps1:53 char:27
+ $MLgroupAll = Get-adgroup <<<< -Properties managedby, enabled, name -filter
{managedby -eq $name}
+ CategoryInfo : ObjectNotFound: (Get-adgroup:String) [], CommandN
otFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
这里是我的代码,我试图找到具有该名称ML *
Import-Module ActiveDirectory
$name = "ML*"
#Attempt 1
$MLgroups = Get-adgroup -Properties managedby, enabled, name -filter * | Select name, managedby
foreach ($group in $MLgroups){
if ($group.managedby -like "ML*"){
write-host $group.name + $group.managedby}
}
#Attempt 2
$Mgroups = get-adgroup -Properties name, managedby -filter *
foreach ($groups in $Mgroups){
# here get the group name and use the "managedBy attribute to retrieve the user object
# grou naem
$gname = $_.Name
$manager=Get-AdUser $_.ManagedBy
$MangerName = $manager.DisplayName
if ($managerName -like "ML*"){
write-host $gname + $managerName}
}
#Attempt 3
$exportlist = "C:\Temp\managedby.txt"
Clear-Content $exportlist
$Header = `
"Group ID Name" + "|" + "ManagedBy"
$Header | Out-File $exportlist -Append
$list = get-adgroup -properties name, managedby -filter {managedby -like "ML_*"} `
| Select name, managedby | Export-CSV $exportlist -NoType -Delimiter '|'
#Attempt 4
$MLgroupAll = Get-adgroup -Properties managedby, enabled, name -filter {managedby -like $name}
foreach ($group in $MLgroupAll) {
write-host $group.name + $group.managedby}
UPDATE业主:如果我尝试改变了我的名字$变量它仍然不起作用,并给出了另一个错误。
$MLgroupAll = get-adgroup -Properties managedby, enabled, name -filter {managedby -eq $name}
foreach ($group in $MLgroupAll) {
$managed = $group.managedby
if ($managed -like "ML*"){
write-host $group.name + $group.managedby }
}
错误: 获取-广告组:在扩展属性提供的身份信息:“的ManagedBy”库仑 □不得到解决。原因:'找不到具有标识''ML *'的对象:'D C = we,DC = dirsrv,DC = com'。'。
@保罗:这是我的错误依然:
'术语“GET -adgroup'不被识别为cmdlet的名称'我以为你需要解决这个问题之前,你担心任何脚本。看起来不像找到cmdlet。 – arco444
我之前在某些程序中使用了get-adgroup,因此在获取该错误对我没有多大意义之前 – narue1992
请参阅您尝试执行的操作的问题是,managedby属性包含DistinguishedName,您将遇到困难将DN与“ML *”之类进行比较。你可以尝试的是'get-aduser ml *',然后获取用户的DN并将其与managedby属性进行比较(如果有帮助的话)。或者使用你的最后一个例子在ML之前添加第二个星号,就像循环中的'$ managed -like“* ML *”' – Paul