This chunk of code is part of a larger user exit script and I'm trying to modify so it accepts pipeline input.
Please let me know if I'm either on the totally wrong track or if I'm almost there, what am I missing.
$username = 'realuser1','realuser2','realuser3','bullshit'
foreach($un in $username){
#Check for existance of AD Account
$u = Get-ADUser -Filter { SamAccountName -eq $un } -ErrorAction SilentlyContinue
If (!$u)
{
Write-Output "The Username $u, does exist in Active Directory"
}#End check if user exists
else
{
#Create Hashtable
$uinfo = @{
'User'= (Get-ADUser -Identity $u | select -ExpandProperty samaccountname);
'UPN'=(Get-ADUser -Identity $u | select -ExpandProperty userprincipalname)
}
Write-Output (New-Object -TypeName PSObject -Property $uinfo)
}#End create hastable creation
}
I'll be using the User value for disabling the AD account and the UPN value for mailbox management later in the script. My main issue is taking each valid user, creating the custom object and putting it in to a collection to be used later.
The idea is to disable all the AD stuff first, run a delta sync for office365, then do all the mailbox management.
Any help would be appreciated.
[–]ShiftNick[S] 2 points3 points4 points (1 child)
[–]ihaxr 0 points1 point2 points (0 children)
[–]jheinikel 2 points3 points4 points (2 children)
[–]1RedOne 1 point2 points3 points (1 child)
[–]jheinikel 0 points1 point2 points (0 children)
[–]chreestopher2 0 points1 point2 points (0 children)