locked
Running Powershell Scripts During OOBE RRS feed

  • Question

  • Good Afternoon,

    For the life of me I cannot determine why I am unable to run powershell scripts from my answer file during the oobeSystem Phase as part of the FirstLogonCommands. Relivent portions of the answer file are below:

    settings pass="oobeSystem">
            <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  
           <FirstLogonCommands>
           <RunSynchronousCommand wcm:action="add">
                        <Description>Set Powershell Execution Policy to Unrestricted</Description>
                        <Path>powershell.exe Set-ExecutionPolicy Unrestricted -force</Path>
                        <Order>3</Order>
             </RunSynchronousCommand>

             </SynchronousCommand>
                    <SynchronousCommand wcm:action="add">
                        <Order>4</Order>
                        <CommandLine>powershell.exe -File &quot;C:\Logs\EnableKeyboardAndMouse.ps1&quot;</CommandLine>
                        <Description>Enable Keyboard and Mouse</Description>
             </SynchronousCommand>

             <SynchronousCommand wcm:action="add">
                        <CommandLine>powershell.exe -File &quot;C:\Logs\OrganizeStartMenu.ps1&quot;</CommandLine>
                        <Order>5</Order>
                        <Description>Remove Un-Needed Start Menu Items</Description>
             </SynchronousCommand>

    </FirstLogonCommands>

    A few interesting notes:

    • Confirmed all files are accessable
    • Files can be run from the command line when I type out the exact same command, ie powershell.exe -File "C:\Logs\OrganizeStartMenu.ps1" and they operate as expected
    • The commands are being run as a local administrator during the setup phase, the account should have permissions to run the scripts.

    Your insights are appreciated!

    -Kevin

     

    Tuesday, April 6, 2010 8:49 PM

Answers

  • No Idea why but changing the command line to "cmd.exe /c "powershell.exe pathToScript" has resolved the issue.
    • Marked as answer by Kevin Kirwin Wednesday, April 7, 2010 8:18 PM
    Wednesday, April 7, 2010 8:18 PM

All replies

  • I would say it is due to powershell execution policy being set to restricted by default. Therefore it will stop any scripts from executing.

    Tuesday, April 6, 2010 9:09 PM
  • Sborys, the 3rd task I run sets the execution policy to unrestricted. I have confirmed that the setting works manually during the oobe process.

    Good idea though :)

    Tuesday, April 6, 2010 9:16 PM
  • Ack ! my eyes fail me, can't believe i missed it.

    Tuesday, April 6, 2010 9:26 PM
  • No Idea why but changing the command line to "cmd.exe /c "powershell.exe pathToScript" has resolved the issue.
    • Marked as answer by Kevin Kirwin Wednesday, April 7, 2010 8:18 PM
    Wednesday, April 7, 2010 8:18 PM