以下是我目前嘗試將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