Below I have a PS command to get some useful user info. I want also have the input from a csv file with PC names. How can I give everything the same format?
The colon after PC name is not the same as I've got from the output from get-aduser
. Can someone advise me what to do?
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)
CodePudding user response:
You can construct an object that merges the AD User with the information coming from your CSV and the information from net user
. Here is an example of how you can approach it:
$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 ($Username -notcontains $Processes)