0 votes

Hi

Using 2018.1 (3.9.15631.0) I'm not sure if this is an issue as such, or if it is a known thing with the Adaxes powershell commands but when using the Move-AdmObject command within a Try statement, if the command fails the error is not caught.

Thanks

by (2.0k points)
0

Hello,

For troubleshooting purposes, could you post here or send us (support[at]adaxes.com) the script you are using?

0

Sure, the script I was using is

Import-Module Adaxes
$TargetPath = "%adm-CustomAttributeText1%"
$Context.LogMessage("Target OU is $TargetPath", "Information")
try { Move-AmdObject -Identity "%objectGUID%" -TargetPath $TargetPath }
catch { $Context.LogMessage("Failed to move the user with error $Error[0]", "Error") }

Where %adm-CustomAttributeText1% has been set earlier in the process and the value is correct in the log file.
If I import the Adaxes module in Powershell directly and fudge the GUID to a non valid one, I get the error

 Move-ADMObject : Can't find an object with identity 'invalid guid'.  
 At C:\\Users\\...\\Desktop\\TestUserMove.ps1:8 char:7  
 + try { Move-ADMObject -Identity $testguid -TargetPath $Destination }  
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  + CategoryInfo : ObjectNotFound: (:) \[Move-AdmObject\], IdentityResolvingException  
  + FullyQualifiedErrorId : Softerra:Adaxes:PowerShellModule:Commands:MoveAdmObjectCommandExecutor:ProcessRecord:IdentityNotResolved,Softerra.Adaxes.PowerShell  
  Module.Commands.MoveAdmObjectCommand

The Catch statement is never executed.

Thanks

1 Answer

0 votes
by (294k points)
selected by
Best answer

Hello,
You need to set the ErrorAction parameter to stop for the cmdlet. For details about the parameter, check the following article on Microsoft blog: https://blogs.technet.microsoft.com/hey ... shell-way/. Your script will be like the following:

Import-Module Adaxes
$TargetPath = "%adm-CustomAttributeText1%"
$Context.LogMessage("Target OU is $TargetPath", "Information")

try 
{
    Move-AdmObject -Identity "%objectGUID%" -TargetPath $TargetPath -ErrorAction stop
}
catch 
{
    $Context.LogMessage("Failed to move the user with error $Error[0]", "Error") 
}

Also, make sure that you enter the correct cmdlet. It should be Move-AdmObject, not Move-AmdObject.

0

Thanks for the info, I'll try adding the erroraction and see see what happens.

Additional quick question, would it work if I were to change the process to use the inbuilt 'Move the User' action and set the destination to %adm-CustomAttributeText1%?

0

Hello,

Yes, it will work fine. Just make sure that the custom attribute of the user account for which the action is executed is set to the distinguished name (DN) of the target container.

0

Brill, I'll use than instead then, will make it all easier :D

Related questions

0 votes
1 answer

seting up a scheduled task to move users to thier correct OU. For some we can do this based on employee type and direct to a specific OU. For most of our users we will have to script this to move to the manager's OU.

asked Apr 12, 2023 by mightycabal (1.0k points)
0 votes
1 answer

After disable user, not user found or show when try to enable...i follow and try many way yet still not showing.. please help i;m using the ... -not-show-disabled-account https://www.adaxes.com/help/PreventUsersFromViewingTheStructure/#change-top-level-node

asked Oct 23, 2023 by kimtienh (20 points)
0 votes
1 answer

Is it possible to have a business rule of the form: IF (company = "Company1") then set City = "New York" set Manager = "New York Manager" If (state = "CO") then set telephone "303" else if (state = "NY") set telephone "202" else clear telephone end if end if

asked Aug 23 by Jiver (20 points)
0 votes
1 answer

Can I get some help with a PowerShell if statement? I'm looking to write something like If the script/custom command is fired via a scheduled task do this. If/Else the ... eq "My Scheduled Task") {"Do Something"} Else {Do Something Different"} Thanks! Ryan

asked Jun 5, 2019 by ryan_breneman (920 points)
0 votes
1 answer

Hi , i have move action I want ADAXES to Remove user from group named like this ADG1 and add user to ADG2 if user moved from OU ADG1 to ADG2 , ... member of group named like this shift_check_in_1 i want to remove and add anohter group named shift_check_in_2

asked Dec 5 by vagifazari (450 points)
3,588 questions
3,277 answers
8,303 comments
548,085 users