【发布时间】:2022-01-26 12:21:19
【问题描述】:
下面我有一个 PS 命令来获取一些有用的用户信息。我还想从带有 PC 名称的 csv 文件中获得输入。我怎样才能为所有内容提供相同的格式?
PC 名称后的冒号与我从get-aduser 的输出中得到的不同。有人可以告诉我该怎么做吗?
Clear-Host
do {
write-Host " Enter the user ID: " -ForegroundColor Cyan -NoNewline
$UserName = Read-Host
Write-Host ""
Get-ADUser -Identity $Username -Properties * | Select-Object DisplayName, mail, LastLogonDate, LastBadPasswordAttempt, AccountExpirationDate, PasswordLastSet , OfficePhone, Department, Manager
$Processes = Import-CSV 'C:\Users\w0vlnd\Desktop\Powershells\Computers in a specific workgroup or domain.csv'
$processes | where "User ID" -like $Username | Select-Object "PC name"
net user $Username /domain | find "Password expires"
net user $Username /domain | find "Password changeable"
write-host "`n"
} while ($Username -notcontains $Processes)
【问题讨论】:
-
您通过
net user $UserName获得的最后两项...数据来自哪里?我在为Get-ADUser列出的属性中找不到它,但我可以在Get-LocalUser的输出中找到它。 -
我很困惑。您的问题是
Net user和Get-ADUser的结果不适合同一用户吗? -
不是数据没有对齐,而是格式/布局不一样……
-
使用 netuser 命令获取我无法从 get-aduser 获取的数据。我从 csv 文件中获得了电脑名称
标签: powershell layout format get-aduser