这个脚本几乎已经完成了,但是我在某些时候总是出错。
下面给我:
Get-ADUser:找不到与参数名称“eq”匹配的参数。位于行:8 字符:37
- $用户=获取AD用户-过滤器已启用-eq $ true-属性SamAccountN ...
~~~
- CategoryInfo:InvalidArgument:(:) [Get-ADUser],ParameterBindingException
- FullyQualifiedErrorId:NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser
任何能解决此问题的帮助都将不胜感激。
# Import the Active Directory module
Import-Module ActiveDirectory
# Specify the output file path for the CSV
$csvFilePath = "C:\test\UsersInfo.csv"
# Get users with empty Manager or Title fields and are active
$users = Get-ADUser -Filter {(Manager -eq * -or Title -eq *)} -and (Enabled -eq $true) -Properties SamAccountName, DisplayName, Manager, Title
# Export the user information to a CSV file
$users | Select-Object SamAccountName, DisplayName, Manager, Title | Export-Csv -Path $csvFilePath -NoTypeInformation
Write-Host "User information exported to $csvFilePath"
答案1
使用命令-Filter
中的参数Get-ADUser
来检索已启用的帐户,并通过管道Where-Object
过滤并获取具有null
以下值的对象:经理' 或者 '标题' 特性。
电源外壳
# Specify the output file path for the CSV
$csvFilePath = "C:\test\UsersInfo.csv"
# Get users with empty Manager or Title fields and are active
$users = Get-ADUser -Filter 'enabled -eq $true' -Properties SamAccountName, DisplayName, Manager, Title | Where-Object {$_.Manager -eq $null -or $_.Title -eq $null}
# Export the user information to a CSV file
$users | Select-Object SamAccountName, DisplayName, Manager, Title | Export-Csv -Path $csvFilePath -NoTypeInformation
Write-Host "User information exported to $csvFilePath"