【发布时间】:2020-01-16 19:46:16
【问题描述】:
我编写了一个代码,但无法将其导出到 csv。 因此,该代码将 AD 用户列表与通讯组或通讯组数量进行比较,并且运行良好。我只能将其导出为 .csv。
Get-ADUser -filter {Enabled -eq $true} -SearchBase "OU=Location" |% { $_.samAccountName } | out-file "C:\users.txt"
Get-ADGroupMember -Identity "Company" |% { $_.samAccountName } | out-file "C:\Members.txt"
$List = Get-Content ("C:\Members.txt")
$ListOfUsers = Get-Content ("C:\users.txt")
$compare = Compare-Object -ReferenceObject $ListOfUsers -DifferenceObject $List -IncludeEqual
foreach($Inp in $compare)
{
$notice = $Inp.InputObject
If ($Inp.SideIndicator -eq "==")
{
"$notice User is avaiable in Distribution List"
}
elseIf ($Inp.SideIndicator -eq "<=")
{
"$notice User is not available in Distribution List "
}
}
如果我在 export-csv 行的末尾添加它会给我这样的东西:
我的问题是: 如果用户是否在分发组内,如何正确导出以接收 InputObject 作为名称、SideIndicator 作为通知和比较运算符作为信息?
【问题讨论】:
-
你能用你想要的输出的例子来澄清你的问题吗?
标签: powershell active-directory