输出 CSV 文件和网络用户命令与 PS 命令不一致

Output CSV file and net user command not aligned with PS command

下面我有一个 PS 命令来获取一些有用的用户信息。我还想从带有 PC 名称的 csv 文件中输入。我怎样才能让所有内容都具有相同的格式?

PC 名称后的冒号与我从 get-aduser 的输出中得到的不一样。有人可以告诉我该怎么做吗?

Example of what I've got

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)

您可以构建一个 对象,将 AD 用户与来自您的 CSV 的信息和来自 net user 的信息合并。这是您如何处理它的示例:

$csv = Import-CSV 'path\to\csvhere.csv'
$ADprops = @(
    'DisplayName'
    'mail'
    'LastLogonDate'
    'LastBadPasswordAttempt'
    'AccountExpirationDate'
    'PasswordLastSet'
    'OfficePhone'
    'Department'
    'Manager'
)

$filter = @(
    $ADprops
    @{
        Name = 'PC Name'
        Expression = { $pcName }
    }, @{
        Name = 'Password Changeable'
        Expression = { $changeable }
    }, @{
        Name = 'Password Expires'
        Expression = { $expires }
    }
)

Clear-Host
do
{
    Write-Host " Enter the user ID: " -ForegroundColor Cyan -NoNewline
    $UserName = Read-Host
    Write-Host ""

    $pcName = $csv.Where({ $_."User ID" -match $Username })."PC Name"
    $expires, $changeable = net user $Username /domain |
    Select-String -Pattern 'Password Changeable|Password Expires' |
    ForEach-Object { ($_ -split '\s{2,}')[1] }
    Get-ADUser -Identity $Username -Properties $ADprops |
    Select-Object $filter

} while ($csv.'User ID' -notcontains $Username)