8 Replies Latest reply on Jul 2, 2014 8:54 AM by jkiuttu27

    Run powershell script after domain join with Provisioning

    jaericho Apprentice

      With Provisioning, I'd like to run a powershell script after the workstation joins the domain. The script adds an AD group to the local admin's. I've thought about doing this on the build, but joining to the domain kicks me out of Audit mode when I am building the image and I'd like to avoid that if possible.

       

      Can I run a powershell script from provisioning? Is there a better way I should do this?

       

      (the workstations are win7 x86)

        • 1. Re: Run powershell script after domain join with Provisioning
          Apprentice

          Yes you can run a powershell script in provisioning.  Just use an execute file action to run powershell and point it at your ps1 file in the command parameters.  Don't forget powershell script execution is disabled by default in Win7 so you'll need to run the command to enable this first.

           

          Steve

          • 2. Re: Run powershell script after domain join with Provisioning
            mbaney Apprentice

            Hi,

             

            I have been having a lot of trouble getting powershell scripts to run in provisioning.  I'm sure I am missing something simple but any help would be appreciated.  No matter how I seem specific the action as step in provisioning I always get an error saying that powershell can’t be found.  I have attached 2 screen shots.  The first shows the error in provisioning along with a directory listing showing that it is in fact present.  The second shows my provisioning step, configured as you state above.  I set the execution policy as one of the first things I do in provisioning.  I have verified this is working.  The full path in the provisioning step for the execute script is "%%windir%%\system32\WindowsPowerShell\v1.0\powershell.exe".  I ahve also tried setting the path explicitly. 

             

            Thanks,

            Brad

             

            pro_error.png

            provisioning.png

            • 3. Re: Run powershell script after domain join with Provisioning
              Apprentice

              When Provisioning tells you it can't find the file you're telling it to run, in this case powershell.exe, its usually leading you down the garden path!  It's far more likely that the problem is with the command parameters - the location of the powershell script.  My first guess would be the fact that there are spaces in path to your ps1 file and you've not used quotes. 

               

              I would suggest running the command manually outside of provisioning first to ensure syntax problems like this aren't going to sneak up and bite you.  Also, I can't see if you've enabled powershell script execution.  By default this is off so it still wouldn't work.

               

              I've attached a template I've used a few times in the past that faciltates powershell usage, it should give you some pointers ;-)

               

              Steve

              • 4. Re: Run powershell script after domain join with Provisioning
                mbaney Apprentice

                Hi,

                 

                Thanks for your help and I am sorry for my slow reply.  I looked at your template it and seems you are just calling ‘powershell’, without the .exe. I tried this, as well as ‘powershell.exe’, but I always get the same result Error: 8001000H file powershell.exe not found.  I have attached a screenshot showing a successfully execution from a command prompt which represents exactly how I am calling the file from within provisioning.  Target path and file name is either powershell.exe or the full path to it and the command line paramters are

                 

                -NonInteractive -NoProfile "&'C:\Program Files (x86)\LANDesk\LDClient\sdmcache\osinstall\pow.ps1'"

                 

                This has really been driving me nuts!  Powershell scripts in software distribution work fine but I can’t use that since this script uses passwords and I am taking advantages of the sensitive data action variables.

                 

                Any help would be greatly appreciated.

                Thanks,

                Brad

                ProPower.png

                • 5. Re: Run powershell script after domain join with Provisioning
                  mbaney Apprentice

                  Hi,

                   

                  So it looks like the only way to get PowerShell scripts under Provisioning to run is to use a GPO to change the execution policy of PowerShell.  The GPO is Computer Configureation->Policies->Administrative Templates->Windows Components->Windows PowerShell->Turn on Script Execution.  Because I don’t believe this actually makes the system any more secure (a batch file can do just as much damage), have many PowerShell scripts, and will make many more PowerShell scripts, I have set this to ‘Allow all scripts’.  Changing the execution policy earlier in provisioning to ‘unrestricted’ does not work.  I tried signing the script file per http://community.landesk.com/support/docs/DOC-25237 but even that didn't work.  Despite what that link says that test is invalid. Provisioning seems to operate under some other profile, settings, rules, or whatever that makes testing very difficult and time consuming.  See my screenshot which shows Provisioning failing to execute a script despite the execution policy being set to unrestricted as well as the script being signed.

                   

                  Thanks,

                  Brad

                  • 7. Re: Run powershell script after domain join with Provisioning
                    Employee

                    I know this is old but some people mihgt still go through this issue. You do not need to change the execution policy on the machines, just let Provisioning run powershell.exe with the following parameter "-executionpolicy bypass -File ScriptFile.ps1

                    • 8. Re: Run powershell script after domain join with Provisioning
                      Rookie

                      Peace  This is great information.  This is actually the first time I have seen this listed or posted regarding running powershell scripts via LANDesk and addressing the execution policy.  I will actually be using this to force Windows Updates via a Windows update Module during the provisioning process along with many other things that can now be explored.  Much appreciated. Thank you!

                       

                      OS Deployment and Provisioning PowerShell