powershell - 脚本中的排序状态(powershell)
问题描述
你好!我有一个脚本可以检查 AD 中的用户,无论他们是否存在。如果它们存在,则在末尾显示“existiert”,如果不存在,则显示“existiert nicht”。在此处输入图像描述 正如您在图片中看到的那样,它没有排序。我如何分类所有存在的都在一起,所有不存在的都在一起。我的脚本在这里:
$UserList = gc "C:\Users\d-phd001\Desktop\AD-Benutzer Checker - Copy\Input\Benutzer&Gruppen_Input.txt"
$outputFilePath = "C:\Users\d-phd001\Desktop\AD-Benutzer Checker - Copy\Output\Benutzer&Gruppen_Output.csv"
$finalResult = foreach ($u in $UserList)
{
$obj = [PSCustomObject]@{
UserName = $u
Status = ""
}
try
{
$ADUser = Get-ADUser -Identity $u -ErrorAction Stop
$obj.Status = "Existiert"
}
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException]
{
$obj.Status = "Existiert Nicht"
}
catch
{
$obj.Status = $_.Exception.Message
}
$obj
}
$finalResult | Export-Csv -Path $outputFilePath -NoTypeInformation -Force
非常感谢!!!
解决方案
用于Sort-Object
对$finalResult
数组进行排序:
$finalResult |Sort-Object -Property Status |Export-Csv -Path $outputFilePath -NoTypeInformation -Force
推荐阅读
- git - git stash 合并到主分支
- javascript - 是否让在 for 循环中创建两个块?
- ios - 放大后 UITextView 字体模糊
- reactjs - 我收到 TypeError:records.map 不是我的反应应用程序中的函数
- android - Android mlkit 条码扫描器提高速度
- reactjs - 将 react-i18next 与 React 独立组件一起使用 - “missingKey”错误
- c - 两个本应兼容的函数指针类型被警告为不兼容。我违反了什么规则?
- python - 如何使用python将随机数转换为十六进制颜色?
- python - 在一个循环的函数上总计所有不同的数字
- linux - 在 docker 镜像上硬编码包版本