User's Manager ValidationValidate a username and password against Active Directory?Return powershell object variable in tableParsing variables into Get-ADUser CMDLT - Error parsing queryMatch the User Name against the Security EventLogUnable to update AD fields with Set-ADUserHow To Ignore Error In Powershell Script (ErrorAction: SilentlyContinue not suppressing error)Active Directory - Get Manager account (from Distinguished Name)AD Account Will Not Create If Duplicate First Name & Second NameDisable users from valid listHow to fix ADD ADGroupMember error “cannot validate argument on a parameter 'Identity', the property is null”

Curve fitting when data has a sharp initial slope and then tapers off

Speeding up thousands of string parses

Is this standard Japanese employment negotiations, or am I missing something?

My players like to search everything. What do they find?

Why weren't Gemini capsules given names?

Sleepy tired vs physically tired

Why do Martians have to wear space helmets?

Why did moving the mouse cursor cause Windows 95 to run more quickly?

What can a novel do that film and TV cannot?

In the Seventh Seal why does Death let the chess game happen?

How to reclaim personal item I've lent to the office without burning bridges?

How to deal with a Murder Hobo Paladin?

How did Einstein know the speed of light was constant?

Machine Learning Golf: Multiplication

What causes a fastener to lock?

Can a Time Lord survive with just one heart?

Why would "dead languages" be the only languages that spells could be written in?

Was the 45.9°C temperature in France in June 2019 the highest ever recorded in France?

Taking advantage when the HR forgets to communicate the rules

What is this arch-and-tower near a road?

Is it bad to suddenly introduce another element to your fantasy world a good ways into the story?

Do Goblin tokens count as Goblins?

PhD: When to quit and move on?

Question about targeting a Hexproof creature



User's Manager Validation


Validate a username and password against Active Directory?Return powershell object variable in tableParsing variables into Get-ADUser CMDLT - Error parsing queryMatch the User Name against the Security EventLogUnable to update AD fields with Set-ADUserHow To Ignore Error In Powershell Script (ErrorAction: SilentlyContinue not suppressing error)Active Directory - Get Manager account (from Distinguished Name)AD Account Will Not Create If Duplicate First Name & Second NameDisable users from valid listHow to fix ADD ADGroupMember error “cannot validate argument on a parameter 'Identity', the property is null”






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am trying to validate if a user has a manager in AD, if it is null/empty, I am supplying a value that it needs to be changed to. I currently have working code if the value isn't null and is different, but am receiving an error if it is null.



I have tried multiple variations on the lookup, but always come back to an error when value is null.



Import-Module ActiveDirectory
if ((Get-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue) -eq $null)
Add-PSSnapin Quest.ActiveRoles.ADManagement

Connect-QADService foo.domain.com

#Specify User, then manager value to check against
Write-Host "What is the user's name?"
$User = Read-Host
Write-Host "Who is the manager we are checking against?"
$manager = Read-Host

#Check if Manager Value is null
if (-not ($ADemanager = (Get-ADUser (Get-ADUser $OBUID -Properties manager).manager).SamAccountName))
Select Name, Manager
else
Write-Host "User's Manager Name not EMPTY in AD."
Write-Host "Checking to see if manager's match in AD."
if ($ADemanager -eq $OBemanager)
#Manager from AD matches manager listed on offboarding form
Write-Host "The manager matches AD Value."
else
Set-ADUser -Manager $OBemanager -PassThru










share|improve this question
























  • where is $OBUID coming from?

    – Lee_Dailey
    Mar 25 at 19:46











  • @Lee_Dailey $OBUID, and $OBemanager are supplied by a form/user input. Sorry forgot to add a write-host section for that in this rendition.

    – Matt
    Mar 26 at 12:23











  • ah! [grin] you really otta add that to your post. as it stands, your code simply CANNOT work since you have a "magic" variable that you didn't assign any value to it. simply add a note to the top about where the undocumented $Var is coming from.

    – Lee_Dailey
    Mar 26 at 16:34











  • Went through and reworked it another way.

    – Matt
    Mar 29 at 18:35











  • kool! glad to know that you got it working as needed ... [grin]

    – Lee_Dailey
    Mar 29 at 18:49

















0















I am trying to validate if a user has a manager in AD, if it is null/empty, I am supplying a value that it needs to be changed to. I currently have working code if the value isn't null and is different, but am receiving an error if it is null.



I have tried multiple variations on the lookup, but always come back to an error when value is null.



Import-Module ActiveDirectory
if ((Get-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue) -eq $null)
Add-PSSnapin Quest.ActiveRoles.ADManagement

Connect-QADService foo.domain.com

#Specify User, then manager value to check against
Write-Host "What is the user's name?"
$User = Read-Host
Write-Host "Who is the manager we are checking against?"
$manager = Read-Host

#Check if Manager Value is null
if (-not ($ADemanager = (Get-ADUser (Get-ADUser $OBUID -Properties manager).manager).SamAccountName))
Select Name, Manager
else
Write-Host "User's Manager Name not EMPTY in AD."
Write-Host "Checking to see if manager's match in AD."
if ($ADemanager -eq $OBemanager)
#Manager from AD matches manager listed on offboarding form
Write-Host "The manager matches AD Value."
else
Set-ADUser -Manager $OBemanager -PassThru










share|improve this question
























  • where is $OBUID coming from?

    – Lee_Dailey
    Mar 25 at 19:46











  • @Lee_Dailey $OBUID, and $OBemanager are supplied by a form/user input. Sorry forgot to add a write-host section for that in this rendition.

    – Matt
    Mar 26 at 12:23











  • ah! [grin] you really otta add that to your post. as it stands, your code simply CANNOT work since you have a "magic" variable that you didn't assign any value to it. simply add a note to the top about where the undocumented $Var is coming from.

    – Lee_Dailey
    Mar 26 at 16:34











  • Went through and reworked it another way.

    – Matt
    Mar 29 at 18:35











  • kool! glad to know that you got it working as needed ... [grin]

    – Lee_Dailey
    Mar 29 at 18:49













0












0








0








I am trying to validate if a user has a manager in AD, if it is null/empty, I am supplying a value that it needs to be changed to. I currently have working code if the value isn't null and is different, but am receiving an error if it is null.



I have tried multiple variations on the lookup, but always come back to an error when value is null.



Import-Module ActiveDirectory
if ((Get-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue) -eq $null)
Add-PSSnapin Quest.ActiveRoles.ADManagement

Connect-QADService foo.domain.com

#Specify User, then manager value to check against
Write-Host "What is the user's name?"
$User = Read-Host
Write-Host "Who is the manager we are checking against?"
$manager = Read-Host

#Check if Manager Value is null
if (-not ($ADemanager = (Get-ADUser (Get-ADUser $OBUID -Properties manager).manager).SamAccountName))
Select Name, Manager
else
Write-Host "User's Manager Name not EMPTY in AD."
Write-Host "Checking to see if manager's match in AD."
if ($ADemanager -eq $OBemanager)
#Manager from AD matches manager listed on offboarding form
Write-Host "The manager matches AD Value."
else
Set-ADUser -Manager $OBemanager -PassThru










share|improve this question
















I am trying to validate if a user has a manager in AD, if it is null/empty, I am supplying a value that it needs to be changed to. I currently have working code if the value isn't null and is different, but am receiving an error if it is null.



I have tried multiple variations on the lookup, but always come back to an error when value is null.



Import-Module ActiveDirectory
if ((Get-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue) -eq $null)
Add-PSSnapin Quest.ActiveRoles.ADManagement

Connect-QADService foo.domain.com

#Specify User, then manager value to check against
Write-Host "What is the user's name?"
$User = Read-Host
Write-Host "Who is the manager we are checking against?"
$manager = Read-Host

#Check if Manager Value is null
if (-not ($ADemanager = (Get-ADUser (Get-ADUser $OBUID -Properties manager).manager).SamAccountName))
Select Name, Manager
else
Write-Host "User's Manager Name not EMPTY in AD."
Write-Host "Checking to see if manager's match in AD."
if ($ADemanager -eq $OBemanager)
#Manager from AD matches manager listed on offboarding form
Write-Host "The manager matches AD Value."
else
Set-ADUser -Manager $OBemanager -PassThru







powershell active-directory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 20:54









Ansgar Wiechers

150k15 gold badges140 silver badges200 bronze badges




150k15 gold badges140 silver badges200 bronze badges










asked Mar 25 at 19:34









MattMatt

104 bronze badges




104 bronze badges












  • where is $OBUID coming from?

    – Lee_Dailey
    Mar 25 at 19:46











  • @Lee_Dailey $OBUID, and $OBemanager are supplied by a form/user input. Sorry forgot to add a write-host section for that in this rendition.

    – Matt
    Mar 26 at 12:23











  • ah! [grin] you really otta add that to your post. as it stands, your code simply CANNOT work since you have a "magic" variable that you didn't assign any value to it. simply add a note to the top about where the undocumented $Var is coming from.

    – Lee_Dailey
    Mar 26 at 16:34











  • Went through and reworked it another way.

    – Matt
    Mar 29 at 18:35











  • kool! glad to know that you got it working as needed ... [grin]

    – Lee_Dailey
    Mar 29 at 18:49

















  • where is $OBUID coming from?

    – Lee_Dailey
    Mar 25 at 19:46











  • @Lee_Dailey $OBUID, and $OBemanager are supplied by a form/user input. Sorry forgot to add a write-host section for that in this rendition.

    – Matt
    Mar 26 at 12:23











  • ah! [grin] you really otta add that to your post. as it stands, your code simply CANNOT work since you have a "magic" variable that you didn't assign any value to it. simply add a note to the top about where the undocumented $Var is coming from.

    – Lee_Dailey
    Mar 26 at 16:34











  • Went through and reworked it another way.

    – Matt
    Mar 29 at 18:35











  • kool! glad to know that you got it working as needed ... [grin]

    – Lee_Dailey
    Mar 29 at 18:49
















where is $OBUID coming from?

– Lee_Dailey
Mar 25 at 19:46





where is $OBUID coming from?

– Lee_Dailey
Mar 25 at 19:46













@Lee_Dailey $OBUID, and $OBemanager are supplied by a form/user input. Sorry forgot to add a write-host section for that in this rendition.

– Matt
Mar 26 at 12:23





@Lee_Dailey $OBUID, and $OBemanager are supplied by a form/user input. Sorry forgot to add a write-host section for that in this rendition.

– Matt
Mar 26 at 12:23













ah! [grin] you really otta add that to your post. as it stands, your code simply CANNOT work since you have a "magic" variable that you didn't assign any value to it. simply add a note to the top about where the undocumented $Var is coming from.

– Lee_Dailey
Mar 26 at 16:34





ah! [grin] you really otta add that to your post. as it stands, your code simply CANNOT work since you have a "magic" variable that you didn't assign any value to it. simply add a note to the top about where the undocumented $Var is coming from.

– Lee_Dailey
Mar 26 at 16:34













Went through and reworked it another way.

– Matt
Mar 29 at 18:35





Went through and reworked it another way.

– Matt
Mar 29 at 18:35













kool! glad to know that you got it working as needed ... [grin]

– Lee_Dailey
Mar 29 at 18:49





kool! glad to know that you got it working as needed ... [grin]

– Lee_Dailey
Mar 29 at 18:49












3 Answers
3






active

oldest

votes


















0














I believe the code snippet below should do what you're asking: determine the current manager of a user, and if it's different from the desired manager (either because a different manager or no manager at all was assigned) update the user object with the new manager.



$ADuser = Get-ADUser $OBUID -Properties Manager
$ADemanager = $ADuser |
Where-Object $_.Manager |
Select-Object -Expand Manager |
Get-ADUser |
Select-Object -Expand SamAccountName

if ($ADemanager -ne $OBemanager)
$ADuser





share|improve this answer

























  • Still received an error based off of this. Select-Object : Cannot process argument because the value of argument "obj" is null. Change the value of argument "obj" to a non-null value. At line:15 char:15 + Select-Object -Expand Manager | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Select-Object], PSArgumentNullException + FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.SelectObjectCommand

    – Matt
    Mar 26 at 12:27











  • @Matt Filter out results with empty/missing property Manager before expanding the property. See updated answer.

    – Ansgar Wiechers
    Mar 26 at 12:58


















0














I think it's easier to grab the correct manager's account and compare that with the user's manager - the following will work.



To write out an incorrect manager's name from the user's properties, I've just got a little -replace to shorten the distiguished name to the account CN. It helps if that matches your samAccountName. If they don't and you really want the samAccountName, you'll need another Get-ADUser for that purpose, but it seems a bit inefficient.



$ADuser = Get-ADUser $OBUID -Properties Manager
# look up the manager account from user input
$OBemanager = Get-ADuser $mgrID

if ($ADuser.manager -eq $OBemanager) #this will match the manager DN
Write-Host "The manager matches AD Value."

else
Get-ADUser -Properties Manager





share|improve this answer

























  • I attempted this and it's set to change the manager's manager entry.

    – Matt
    Mar 26 at 13:35











  • It was a typo in the write-host where it outputs what it is going to do. I've fixed it now (it would have done the update correctly)

    – Trix
    Mar 27 at 0:25


















0














So I reworked the issue another way.



Most of the variables are loaded from a form, along with the



 $OBmanager = $cmbOBManager.Text.Split(",")
$OBmanagername = $OBmanager[0]
$OBemanager = $OBmanager[1].Trim()
$OBestring = "@iconectiv.com"
$OBEmpManager = $OBemanager + $OBestring


#-check if manager from offboarding form is same listed in AD
#Check User's manager name
$userEntry = get-qaduser $OBUID
[string]$man = $userEntry.manager
#Check if manager name is null
if (-not ($man -eq $null))
{
[array]$manName = $man.split('=,')
$manager = $manName[1]
#If null, change to HR specified value
If($manager -eq $null)

Write-Host "The user's manager is Null in AD."
Write-Host "Changing the user's manager to the HR supplied value."
Get-aduser $OBUID
else

Write-Host "$manager is the manager of $OBUID";
$ADemanager = (get-aduser (get-aduser $OBUID -Properties manager).manager).samaccountName
#Check if AD value is the same as HR value
If($ADemanager -eq $OBemanager)

Write-Host "The HR manager name supplied value matches the AD Value."

else

Write-Host "The HR manager name supplied value doesn't match the AD Value."
Write-Host "Changing the manager value in AD to the HR supplied value."
Get-aduser $OBUID






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345205%2fusers-manager-validation%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I believe the code snippet below should do what you're asking: determine the current manager of a user, and if it's different from the desired manager (either because a different manager or no manager at all was assigned) update the user object with the new manager.



    $ADuser = Get-ADUser $OBUID -Properties Manager
    $ADemanager = $ADuser |
    Where-Object $_.Manager |
    Select-Object -Expand Manager |
    Get-ADUser |
    Select-Object -Expand SamAccountName

    if ($ADemanager -ne $OBemanager)
    $ADuser





    share|improve this answer

























    • Still received an error based off of this. Select-Object : Cannot process argument because the value of argument "obj" is null. Change the value of argument "obj" to a non-null value. At line:15 char:15 + Select-Object -Expand Manager | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Select-Object], PSArgumentNullException + FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.SelectObjectCommand

      – Matt
      Mar 26 at 12:27











    • @Matt Filter out results with empty/missing property Manager before expanding the property. See updated answer.

      – Ansgar Wiechers
      Mar 26 at 12:58















    0














    I believe the code snippet below should do what you're asking: determine the current manager of a user, and if it's different from the desired manager (either because a different manager or no manager at all was assigned) update the user object with the new manager.



    $ADuser = Get-ADUser $OBUID -Properties Manager
    $ADemanager = $ADuser |
    Where-Object $_.Manager |
    Select-Object -Expand Manager |
    Get-ADUser |
    Select-Object -Expand SamAccountName

    if ($ADemanager -ne $OBemanager)
    $ADuser





    share|improve this answer

























    • Still received an error based off of this. Select-Object : Cannot process argument because the value of argument "obj" is null. Change the value of argument "obj" to a non-null value. At line:15 char:15 + Select-Object -Expand Manager | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Select-Object], PSArgumentNullException + FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.SelectObjectCommand

      – Matt
      Mar 26 at 12:27











    • @Matt Filter out results with empty/missing property Manager before expanding the property. See updated answer.

      – Ansgar Wiechers
      Mar 26 at 12:58













    0












    0








    0







    I believe the code snippet below should do what you're asking: determine the current manager of a user, and if it's different from the desired manager (either because a different manager or no manager at all was assigned) update the user object with the new manager.



    $ADuser = Get-ADUser $OBUID -Properties Manager
    $ADemanager = $ADuser |
    Where-Object $_.Manager |
    Select-Object -Expand Manager |
    Get-ADUser |
    Select-Object -Expand SamAccountName

    if ($ADemanager -ne $OBemanager)
    $ADuser





    share|improve this answer















    I believe the code snippet below should do what you're asking: determine the current manager of a user, and if it's different from the desired manager (either because a different manager or no manager at all was assigned) update the user object with the new manager.



    $ADuser = Get-ADUser $OBUID -Properties Manager
    $ADemanager = $ADuser |
    Where-Object $_.Manager |
    Select-Object -Expand Manager |
    Get-ADUser |
    Select-Object -Expand SamAccountName

    if ($ADemanager -ne $OBemanager)
    $ADuser






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 26 at 12:58

























    answered Mar 25 at 21:01









    Ansgar WiechersAnsgar Wiechers

    150k15 gold badges140 silver badges200 bronze badges




    150k15 gold badges140 silver badges200 bronze badges












    • Still received an error based off of this. Select-Object : Cannot process argument because the value of argument "obj" is null. Change the value of argument "obj" to a non-null value. At line:15 char:15 + Select-Object -Expand Manager | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Select-Object], PSArgumentNullException + FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.SelectObjectCommand

      – Matt
      Mar 26 at 12:27











    • @Matt Filter out results with empty/missing property Manager before expanding the property. See updated answer.

      – Ansgar Wiechers
      Mar 26 at 12:58

















    • Still received an error based off of this. Select-Object : Cannot process argument because the value of argument "obj" is null. Change the value of argument "obj" to a non-null value. At line:15 char:15 + Select-Object -Expand Manager | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Select-Object], PSArgumentNullException + FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.SelectObjectCommand

      – Matt
      Mar 26 at 12:27











    • @Matt Filter out results with empty/missing property Manager before expanding the property. See updated answer.

      – Ansgar Wiechers
      Mar 26 at 12:58
















    Still received an error based off of this. Select-Object : Cannot process argument because the value of argument "obj" is null. Change the value of argument "obj" to a non-null value. At line:15 char:15 + Select-Object -Expand Manager | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Select-Object], PSArgumentNullException + FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.SelectObjectCommand

    – Matt
    Mar 26 at 12:27





    Still received an error based off of this. Select-Object : Cannot process argument because the value of argument "obj" is null. Change the value of argument "obj" to a non-null value. At line:15 char:15 + Select-Object -Expand Manager | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Select-Object], PSArgumentNullException + FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.SelectObjectCommand

    – Matt
    Mar 26 at 12:27













    @Matt Filter out results with empty/missing property Manager before expanding the property. See updated answer.

    – Ansgar Wiechers
    Mar 26 at 12:58





    @Matt Filter out results with empty/missing property Manager before expanding the property. See updated answer.

    – Ansgar Wiechers
    Mar 26 at 12:58













    0














    I think it's easier to grab the correct manager's account and compare that with the user's manager - the following will work.



    To write out an incorrect manager's name from the user's properties, I've just got a little -replace to shorten the distiguished name to the account CN. It helps if that matches your samAccountName. If they don't and you really want the samAccountName, you'll need another Get-ADUser for that purpose, but it seems a bit inefficient.



    $ADuser = Get-ADUser $OBUID -Properties Manager
    # look up the manager account from user input
    $OBemanager = Get-ADuser $mgrID

    if ($ADuser.manager -eq $OBemanager) #this will match the manager DN
    Write-Host "The manager matches AD Value."

    else
    Get-ADUser -Properties Manager





    share|improve this answer

























    • I attempted this and it's set to change the manager's manager entry.

      – Matt
      Mar 26 at 13:35











    • It was a typo in the write-host where it outputs what it is going to do. I've fixed it now (it would have done the update correctly)

      – Trix
      Mar 27 at 0:25















    0














    I think it's easier to grab the correct manager's account and compare that with the user's manager - the following will work.



    To write out an incorrect manager's name from the user's properties, I've just got a little -replace to shorten the distiguished name to the account CN. It helps if that matches your samAccountName. If they don't and you really want the samAccountName, you'll need another Get-ADUser for that purpose, but it seems a bit inefficient.



    $ADuser = Get-ADUser $OBUID -Properties Manager
    # look up the manager account from user input
    $OBemanager = Get-ADuser $mgrID

    if ($ADuser.manager -eq $OBemanager) #this will match the manager DN
    Write-Host "The manager matches AD Value."

    else
    Get-ADUser -Properties Manager





    share|improve this answer

























    • I attempted this and it's set to change the manager's manager entry.

      – Matt
      Mar 26 at 13:35











    • It was a typo in the write-host where it outputs what it is going to do. I've fixed it now (it would have done the update correctly)

      – Trix
      Mar 27 at 0:25













    0












    0








    0







    I think it's easier to grab the correct manager's account and compare that with the user's manager - the following will work.



    To write out an incorrect manager's name from the user's properties, I've just got a little -replace to shorten the distiguished name to the account CN. It helps if that matches your samAccountName. If they don't and you really want the samAccountName, you'll need another Get-ADUser for that purpose, but it seems a bit inefficient.



    $ADuser = Get-ADUser $OBUID -Properties Manager
    # look up the manager account from user input
    $OBemanager = Get-ADuser $mgrID

    if ($ADuser.manager -eq $OBemanager) #this will match the manager DN
    Write-Host "The manager matches AD Value."

    else
    Get-ADUser -Properties Manager





    share|improve this answer















    I think it's easier to grab the correct manager's account and compare that with the user's manager - the following will work.



    To write out an incorrect manager's name from the user's properties, I've just got a little -replace to shorten the distiguished name to the account CN. It helps if that matches your samAccountName. If they don't and you really want the samAccountName, you'll need another Get-ADUser for that purpose, but it seems a bit inefficient.



    $ADuser = Get-ADUser $OBUID -Properties Manager
    # look up the manager account from user input
    $OBemanager = Get-ADuser $mgrID

    if ($ADuser.manager -eq $OBemanager) #this will match the manager DN
    Write-Host "The manager matches AD Value."

    else
    Get-ADUser -Properties Manager






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 27 at 0:24

























    answered Mar 26 at 4:35









    TrixTrix

    5362 silver badges13 bronze badges




    5362 silver badges13 bronze badges












    • I attempted this and it's set to change the manager's manager entry.

      – Matt
      Mar 26 at 13:35











    • It was a typo in the write-host where it outputs what it is going to do. I've fixed it now (it would have done the update correctly)

      – Trix
      Mar 27 at 0:25

















    • I attempted this and it's set to change the manager's manager entry.

      – Matt
      Mar 26 at 13:35











    • It was a typo in the write-host where it outputs what it is going to do. I've fixed it now (it would have done the update correctly)

      – Trix
      Mar 27 at 0:25
















    I attempted this and it's set to change the manager's manager entry.

    – Matt
    Mar 26 at 13:35





    I attempted this and it's set to change the manager's manager entry.

    – Matt
    Mar 26 at 13:35













    It was a typo in the write-host where it outputs what it is going to do. I've fixed it now (it would have done the update correctly)

    – Trix
    Mar 27 at 0:25





    It was a typo in the write-host where it outputs what it is going to do. I've fixed it now (it would have done the update correctly)

    – Trix
    Mar 27 at 0:25











    0














    So I reworked the issue another way.



    Most of the variables are loaded from a form, along with the



     $OBmanager = $cmbOBManager.Text.Split(",")
    $OBmanagername = $OBmanager[0]
    $OBemanager = $OBmanager[1].Trim()
    $OBestring = "@iconectiv.com"
    $OBEmpManager = $OBemanager + $OBestring


    #-check if manager from offboarding form is same listed in AD
    #Check User's manager name
    $userEntry = get-qaduser $OBUID
    [string]$man = $userEntry.manager
    #Check if manager name is null
    if (-not ($man -eq $null))
    {
    [array]$manName = $man.split('=,')
    $manager = $manName[1]
    #If null, change to HR specified value
    If($manager -eq $null)

    Write-Host "The user's manager is Null in AD."
    Write-Host "Changing the user's manager to the HR supplied value."
    Get-aduser $OBUID
    else

    Write-Host "$manager is the manager of $OBUID";
    $ADemanager = (get-aduser (get-aduser $OBUID -Properties manager).manager).samaccountName
    #Check if AD value is the same as HR value
    If($ADemanager -eq $OBemanager)

    Write-Host "The HR manager name supplied value matches the AD Value."

    else

    Write-Host "The HR manager name supplied value doesn't match the AD Value."
    Write-Host "Changing the manager value in AD to the HR supplied value."
    Get-aduser $OBUID






    share|improve this answer



























      0














      So I reworked the issue another way.



      Most of the variables are loaded from a form, along with the



       $OBmanager = $cmbOBManager.Text.Split(",")
      $OBmanagername = $OBmanager[0]
      $OBemanager = $OBmanager[1].Trim()
      $OBestring = "@iconectiv.com"
      $OBEmpManager = $OBemanager + $OBestring


      #-check if manager from offboarding form is same listed in AD
      #Check User's manager name
      $userEntry = get-qaduser $OBUID
      [string]$man = $userEntry.manager
      #Check if manager name is null
      if (-not ($man -eq $null))
      {
      [array]$manName = $man.split('=,')
      $manager = $manName[1]
      #If null, change to HR specified value
      If($manager -eq $null)

      Write-Host "The user's manager is Null in AD."
      Write-Host "Changing the user's manager to the HR supplied value."
      Get-aduser $OBUID
      else

      Write-Host "$manager is the manager of $OBUID";
      $ADemanager = (get-aduser (get-aduser $OBUID -Properties manager).manager).samaccountName
      #Check if AD value is the same as HR value
      If($ADemanager -eq $OBemanager)

      Write-Host "The HR manager name supplied value matches the AD Value."

      else

      Write-Host "The HR manager name supplied value doesn't match the AD Value."
      Write-Host "Changing the manager value in AD to the HR supplied value."
      Get-aduser $OBUID






      share|improve this answer

























        0












        0








        0







        So I reworked the issue another way.



        Most of the variables are loaded from a form, along with the



         $OBmanager = $cmbOBManager.Text.Split(",")
        $OBmanagername = $OBmanager[0]
        $OBemanager = $OBmanager[1].Trim()
        $OBestring = "@iconectiv.com"
        $OBEmpManager = $OBemanager + $OBestring


        #-check if manager from offboarding form is same listed in AD
        #Check User's manager name
        $userEntry = get-qaduser $OBUID
        [string]$man = $userEntry.manager
        #Check if manager name is null
        if (-not ($man -eq $null))
        {
        [array]$manName = $man.split('=,')
        $manager = $manName[1]
        #If null, change to HR specified value
        If($manager -eq $null)

        Write-Host "The user's manager is Null in AD."
        Write-Host "Changing the user's manager to the HR supplied value."
        Get-aduser $OBUID
        else

        Write-Host "$manager is the manager of $OBUID";
        $ADemanager = (get-aduser (get-aduser $OBUID -Properties manager).manager).samaccountName
        #Check if AD value is the same as HR value
        If($ADemanager -eq $OBemanager)

        Write-Host "The HR manager name supplied value matches the AD Value."

        else

        Write-Host "The HR manager name supplied value doesn't match the AD Value."
        Write-Host "Changing the manager value in AD to the HR supplied value."
        Get-aduser $OBUID






        share|improve this answer













        So I reworked the issue another way.



        Most of the variables are loaded from a form, along with the



         $OBmanager = $cmbOBManager.Text.Split(",")
        $OBmanagername = $OBmanager[0]
        $OBemanager = $OBmanager[1].Trim()
        $OBestring = "@iconectiv.com"
        $OBEmpManager = $OBemanager + $OBestring


        #-check if manager from offboarding form is same listed in AD
        #Check User's manager name
        $userEntry = get-qaduser $OBUID
        [string]$man = $userEntry.manager
        #Check if manager name is null
        if (-not ($man -eq $null))
        {
        [array]$manName = $man.split('=,')
        $manager = $manName[1]
        #If null, change to HR specified value
        If($manager -eq $null)

        Write-Host "The user's manager is Null in AD."
        Write-Host "Changing the user's manager to the HR supplied value."
        Get-aduser $OBUID
        else

        Write-Host "$manager is the manager of $OBUID";
        $ADemanager = (get-aduser (get-aduser $OBUID -Properties manager).manager).samaccountName
        #Check if AD value is the same as HR value
        If($ADemanager -eq $OBemanager)

        Write-Host "The HR manager name supplied value matches the AD Value."

        else

        Write-Host "The HR manager name supplied value doesn't match the AD Value."
        Write-Host "Changing the manager value in AD to the HR supplied value."
        Get-aduser $OBUID







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 29 at 18:39









        MattMatt

        104 bronze badges




        104 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345205%2fusers-manager-validation%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해