dinci5 Posted October 25, 2016 Report post Posted October 25, 2016 Hi, At the end of my OSD Task Sequence I run a Powershell script that generates a report and saves it in a certain location. Helpdesk uses this report to quickly check if all applications are correctly installed and a few other things. One of the things is a check for the OU of the device. When I run the script from within Windows it works just fine. However, during OS Deployment the OU cannot be read. FYI... The script does not rely on the ActiveDirectory modules. It uses the System.DirectoryServices namespace. Any ideas how to get it to work? Quote Share this post Link to post Share on other sites More sharing options...
Peter33 Posted October 25, 2016 Report post Posted October 25, 2016 Well, i don't know what your script looks like, but this one should work. $filter = "(&(objectCategory=computer)(objectClass=computer)(cn=$env:COMPUTERNAME))" (([adsisearcher]$filter).FindOne().Properties.distinguishedname).replace('CN=' + $env:COMPUTERNAME + ',','') Quote Share this post Link to post Share on other sites More sharing options...
dinci5 Posted October 26, 2016 Report post Posted October 26, 2016 I use this script, but slightly edited for my purposes: https://gallery.technet.microsoft.com/scriptcenter/Retrieve-OU-for-Computer-7a062402 So it's similar to what you posted. Perhaps it's because the script is ran with the SYSTEM account? Quote Share this post Link to post Share on other sites More sharing options...
Peter33 Posted October 28, 2016 Report post Posted October 28, 2016 No, the System account should just work fine. It has the required permissions to read the object attributes from the AD. One way to debug scripts in Task sequnces is to pause the sequnce. Have a look at Nialls Howto here https://www.windows-noob.com/forums/topic/8846-how-can-i-pause-a-task-sequence-in-system-center-2012-configuration-manager/ You can simply then run "powershell ise" from the F8 comman prompt and modify your script until it works as intended. This will save you countless hours of restarting sequences and watching progress bars. Also make sure to dump the values of newly created variables in your script to the Standard Output, just to check if they hold the correct and expected value. Quote Share this post Link to post Share on other sites More sharing options...
dinci5 Posted November 7, 2016 Report post Posted November 7, 2016 No, the System account should just work fine. It has the required permissions to read the object attributes from the AD. One way to debug scripts in Task sequnces is to pause the sequnce. Have a look at Nialls Howto here https://www.windows-noob.com/forums/topic/8846-how-can-i-pause-a-task-sequence-in-system-center-2012-configuration-manager/ You can simply then run "powershell ise" from the F8 comman prompt and modify your script until it works as intended. This will save you countless hours of restarting sequences and watching progress bars. Also make sure to dump the values of newly created variables in your script to the Standard Output, just to check if they hold the correct and expected value. Okey, that is seriously one of the best things there is to troubleshoot TS errors. I will definitely try that one out. Thanks a lot Peter! Quote Share this post Link to post Share on other sites More sharing options...