gerhardub
asked on
PowerShell: Debug Help with User Name Check Using Get-QADUser
Ok,
So what I'm attempting to do is take a user ID stored in $strSamAccountName and check to see if it exists in AD.
If it does, then a result will be stored in $CheckUser.
If it does not, then $CheckUser is $Null, since the Quest Get-QADUser will not find anything.
I also have another variable setup that is for a separate option user ID called $strOptionUID. (This is part of a new user script that uses an Excel form. The requestor can add an option user logon ID if they know there is someone else with the same name in Active Directory.)
Anyway, this code causes me some issues. The output of this code results in the new user ID being "userxyz22;" if the user id exists it's always got a 22 after it.
What I want to do is change the provided user ID to userxyz2, userxyz3, etc. if the ID is in AD.
$Counter = 2
$FoundName = $false
$CheckUser = $null
$CheckUser = Get-QADUser $strSamAccountName
if (($CheckUser -ne $null) -and ($strOptionalUID -eq $null))
{
:UpdateUID do
{
$samAccountTemp = $null
$samAccountTemp = $strSamAccountName + "$Counter"
$CheckUser = Get-QADUser $samAccountTemp
if ($CheckUser -eq $null) {$strSamAccountName = $samAccountTemp + "$Counter";$strUserPrincip alName = $strSamAccountName + "@company.com";$strMailAdd ress = $strUserPrincipalName;$str MailAlias = $strSamAccountName;$FoundN ame = $True}
$Counter = $Counter + 1
}while($FoundName -ne $true)
}
So, what did I do wrong?
GB
So what I'm attempting to do is take a user ID stored in $strSamAccountName and check to see if it exists in AD.
If it does, then a result will be stored in $CheckUser.
If it does not, then $CheckUser is $Null, since the Quest Get-QADUser will not find anything.
I also have another variable setup that is for a separate option user ID called $strOptionUID. (This is part of a new user script that uses an Excel form. The requestor can add an option user logon ID if they know there is someone else with the same name in Active Directory.)
Anyway, this code causes me some issues. The output of this code results in the new user ID being "userxyz22;" if the user id exists it's always got a 22 after it.
What I want to do is change the provided user ID to userxyz2, userxyz3, etc. if the ID is in AD.
$Counter = 2
$FoundName = $false
$CheckUser = $null
$CheckUser = Get-QADUser $strSamAccountName
if (($CheckUser -ne $null) -and ($strOptionalUID -eq $null))
{
:UpdateUID do
{
$samAccountTemp = $null
$samAccountTemp = $strSamAccountName + "$Counter"
$CheckUser = Get-QADUser $samAccountTemp
if ($CheckUser -eq $null) {$strSamAccountName = $samAccountTemp + "$Counter";$strUserPrincip
$Counter = $Counter + 1
}while($FoundName -ne $true)
}
So, what did I do wrong?
GB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you sir!
GB