forked from lazywinadmin/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cec2484
commit 8d5a6bf
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Function Get-SCSMUserManager | ||
{ | ||
Param ( | ||
$input_affectedUser_id | ||
) | ||
|
||
## Return Variables | ||
$managerOfAffectedUser_obj = $null | ||
|
||
## MAIN | ||
$affectedUser_obj = get-scsmobject -id $input_affectedUser_id | ||
$userManagesUser_relclass_id = '4a807c65-6a1f-15b2-bdf3-e967e58c254a' | ||
$managerOfAffectedUser_relobjs = Get-SCSMRelationshipObject -ByTarget $affectedUser_obj | where{ $_.relationshipId -eq $userManagesUser_relclass_id } | ||
|
||
## Check if Manager User Exists and that the relationship is current. | ||
## get-scsmrelationshipobject tends to keep track of relationship history. It returns old and new | ||
## relationships | ||
|
||
If ($managerOfAffectedUser_relobjs -ne $null) | ||
{ | ||
ForEach ($managerOfAffectedUser_relobj in $managerOfAffectedUser_relobjs) | ||
{ | ||
If ($managerOfAffectedUser_relobj.IsDeleted -eq $True) | ||
{ | ||
#The relationship no longer exists. Returning nothing | ||
# which will effectively keep the managerOfAffectedUser_obj the same as before. | ||
} | ||
Else | ||
{ | ||
#The relationship exists, setting managerOfAffectedUser_relExists to true. | ||
$managerOfAffectedUser_id = $managerofaffecteduser_relobj.SourceObject.Id.Guid | ||
$managerOfAffectedUser_obj = get-scsmobject -id $managerofaffecteduser_id | ||
} | ||
} | ||
} | ||
Else | ||
{ | ||
#No Affected User Exists | ||
$managerOfAffectedUser_obj = $null | ||
} | ||
$managerOfAffectedUser_obj | ||
} |