Looking for a script

Hi Everybody

So I need a script to look up users on AD/AAD and exchange on-premis/O365, it needs to show all information I can get :slight_smile:

As I have limited capability in PS I’d like your help, as you probably already have some scripts that can help.

Script purpose: Too help me look up user data/settings for users so I dont have to use multiple tools :stuck_out_tongue:

Hi, welcome to the forum :wave:

We don’t provide scripts on request but would be happy to help you troubleshoot your own scripts and help you learn PowerShell.

What have you tried so far?

Start by reading the help for Get-ADUser

Get-Help Get-ADUser or

2 Likes

So here’s my current script. An easy way for us to look up some user info, But i can seem to get my IF syntax’s correct. It seems like it dosen’t really do the check?

Write-Host Type User initials
$userID= read-host -Prompt "Enter Initials"


write "------------User Info------------"
get-aduser -Identity $nemligID -Properties * | Select CN, Created, Department, Title, DisplayName,EmailAddress,EmpoyeeID,Mobile,Enabled

if ($user.Enabled -eq 'True')
{
Write-Host "Enabled"
Write-Host "OK" -ForegroundColor Green
}

write ""
Write "------------Password------------"
write ""
get-aduser -Identity $userID -Properties * | Select LastBadPasswordAttempt,LockedOut,PasswordLastSet,PasswordNeverExpires

if ($user.LockedOut -match 'False')
{
Write-host "Account is NOT locked"
Write-Host "OK" -ForegroundColor Green
}
else
{
Write-host "Account is locked"
Write-Host "Locked" -ForegroundColor Red
}

Write "------------HomeDrive------------"
Write ""
Get-ADUser -Identity $userID -Properties * | Select HomeDirectory,HomedirRequired,HomeDrive
Write "------------Mail Info------------"
Write ""
Get-ADUser -Identity $userID -Properties * | Select EmailAddress,targetAddress,extensionAttribute15
if ($User.extensionAttribute15 -match 'RemoteMailbox')
{
Write-Host "Attribute15"
Write-Host "OK" -ForegroundColor Green
}
else
{
Write-Host "Attribute15"
Write-Host "Fail" -ForegroundColor Red
}
Write ""
Write "------------AAD Info------------"
Write ""
Get-ADUser -Identity $userID -Properties * | Select BadLogonCount,badPwdCount,CannotChangePassword,CanonicalName,Certificates,Manager,-MemberOf,UserPrincipalName,whenChanged,whenCreated



A few things:

  1. You’re not using $userID in your first Get-ADUser command.
  2. You’re not assigning the result of Get-ADUser to a variable. You should assign it to a variable and then you need only get that user once.
  3. Your if statements are checking for properties of $user but you’re not assigning anything to that variable.

Replace all of your Get-ADUser statements with a single one:

$user = Get-ADUser $userID -Properties * and then do your checks.

Personally, I would replace the * with just the properties I want, but let’s keep it simple for now.

1 Like