Powershell in task sequence

I want to use a PS script in TS. The script should move the current client to a Special OU in AD.

The script is working but, I am having a Problem calling it in a TS. I have to run the script with an domain account which is ahving the rights to move the Client.

Here is the script. Ist working outside the TS:

# Retrieve DN of local computer.
$SysInfo =  New-Object -ComObject  "ADSystemInfo" 
$ComputerDN = $SysInfo.GetType().InvokeMember("ComputerName", "GetProperty", $Null, $SysInfo, $Null) 

# Bind to computer object in AD.
$Computer =  [ADSI]"LDAP://$ComputerDN"

# Specify target OU.
$TargetOU =  "ou=_clients,dc=mydomain,dc=int"

# Bind to target OU.
$OU =  [ADSI]"LDAP://$TargetOU"

# Move computer to target OU.
$Computer.psbase.MoveTo($OU)

September 15th, 2015 2:24am

Why don't you specify the OU in the "Apply Network Settings" Step where you perform the actual Domain Join?
Free Windows Admin Tool Kit Click here and download it now
September 15th, 2015 2:30am

Why don't you specify the OU in the "Apply Network Settings" Step where you perform the actual Do
September 15th, 2015 2:32am

You could try to use the "Run Command Line" Action to call the PowerShell Script. There you can specify a "Run as" Account

You could also try to create multiple "Apply Network Settings" Steps and use conditions for targ

Free Windows Admin Tool Kit Click here and download it now
September 15th, 2015 2:38am

I alreday tried the "Run Command Line" but ist not working. I am always getting errors
September 15th, 2015 2:54am

Hi

ADSI is not available in Windows PE, so if you're attempting to run this in Windows PE part of the task sequence it will fail.

Windows PE does not have the ADSI drivers loaded, this is by design for security reasons by Microsoft.

Free Windows Admin Tool Kit Click here and download it now
September 15th, 2015 3:03am

Hi Kriss,

thx for replying. I built a second TS which is running on an installed system. Also here I am getting the errors.

September 15th, 2015 3:06am

As part of any scripting practice it's a good idea to use error handling and logging so that you're able to troubleshoot problems.

Look into using a logging function for creating a logfile from the script.

Look into using error handling with powershell, using Trap and Try, Catch.

Without any error handling from the script, I can't say for certain what could be failing. At a guess I'd say that within the task sequence ADSystemInfo probably doesn't return the distinguishedname as you're expecting. But as I said, you should use logging and error handling and review the logfile.

Free Windows Admin Tool Kit Click here and download it now
September 15th, 2015 3:27am