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;
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
add a comment |
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
where is$OBUIDcoming 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
add a comment |
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
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
powershell active-directory
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$OBUIDcoming 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
add a comment |
where is$OBUIDcoming 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
add a comment |
3 Answers
3
active
oldest
votes
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
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 propertyManagerbefore expanding the property. See updated answer.
– Ansgar Wiechers
Mar 26 at 12:58
add a comment |
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
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
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 propertyManagerbefore expanding the property. See updated answer.
– Ansgar Wiechers
Mar 26 at 12:58
add a comment |
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
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 propertyManagerbefore expanding the property. See updated answer.
– Ansgar Wiechers
Mar 26 at 12:58
add a comment |
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
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
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 propertyManagerbefore expanding the property. See updated answer.
– Ansgar Wiechers
Mar 26 at 12:58
add a comment |
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 propertyManagerbefore 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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Mar 29 at 18:39
MattMatt
104 bronze badges
104 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
where is
$OBUIDcoming 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