powershell - Powershell get-aduser 格式化 Write-Host
问题描述
我有一个 powershell 脚本,我希望运行并输出格式为:
PS C:\Users\Administrator> Get-ADuser j.citizen
DistinguishedName : CN=John Citizen,CN=Users,DC=mydomain,DC=local
Enabled : True
GivenName : John
Name : John Citizen
ObjectClass : user
ObjectGUID : 3ecc1da4-6443-4e77-b594-3061be28a434
SamAccountName : j.citizen
SID : S-1-5-21-3281199732-950135425-2894168244-1115
Surname : Citizen
UserPrincipalName : j.citizen@mydomain.local
我的 Powershell 代码是:
$varAccount = Get-AdUser j.citizen
Write-Host "$varAccount"
它输出:
CN=John Citizen,CN=Users,DC=mydomain,DC=local
解决方案
然后看看Format-List
$varAccount = Get-AdUser j.citizen
$varAccount | Format-List -Property *
您还可以在变量中捕获此控制台输出,以将其保存在文本文件中,例如:
$output = $varAccount | Format-List -Property * | Out-String
推荐阅读
- excel-formula - 根据excel/google工作表中不同列的数字检索单元格文本
- sql - 如何在 MM-DD 上聚合多年的数据,忽略年份
- c# - 根据左侧的分隔符将字符串拆分为子字符串
- python - Django + 后台任务如何初始化
- javascript - 输入无效时显示工具提示/消息 HTML/JS/CSS/Angularjs
- python - 使用python获取elasticsearch数据库中的唯一字段
- c++ - 未找到所需的 Zlib 库
- sql - SQL查询自定义输出
- angular - 从主页重定向到登录页面时无法隐藏登录页面中的导航栏
- hybris - 在 hybris 后台更改对象标识符