I do regular user checks and occasionally some users have privileged accounts. The attribute that allows me to validate if the standard user has a privileged account is the "comment" attribute. I would like to know how to display the result of the accounts on the same line, separated by ';'
$LoginID = (Read-Host "Please type the USER's Login ID").Trim()
### Check if the user has a priviledge account ###
$admUser = foreach($user in $LoginID){
Get-ADUser -LDAPFilter "(comment=$($user))" -searchbase "OU=Privileged,OU=Accounts,DC=contoso,DC=com" -Properties name, samaccountname
}
$Accounts = if($admUser) {Write-host "The user contains a regular account and a privileged account:" $($admUser.SamAccountName -join ';')$($LoginID)}else{(Write-Host "The user has only a regular account $($LoginID)")}
$Accounts
CodePudding user response:
$Accounts = if($admUser) {"$($admUser.SamAccountName ';')$($LoginID)"}else{$(Write-Host "The user has only a regular account $($LoginID)")}
You can join strings with
You can also Write-Host -NoNewline For output with no new line. I suggest breaking up your one liner to populate strings then write-host the strings with the -nonewline option.