During an unattended installation with WDS, I need to run a script on a share just at the end of pass 7 oobeSystem.
I use the FirstLogonCommands / SynchronousCommand option and provide this command line:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit -ExecutionPolicy Bypass -WindowStyle Maximized -NoProfile -Command {New-SmbMapping -LocalPath z: -RemotePath \\10.10.10.5\Share -Persistent $false -UserName user -Password password; z:\script.ps1}
It opens the PowerShell console, but displays the scriptblock at the top of this window before displaying the command prompt, and unfortunately does not execute the scriptblock.
I tried to introduce a sleep before, but it doesn't change the result.
Here is an example:
How can I fix this?
Best Answer
The
FirstLogonCommands
documentation shows an XML Example how to specify two commands to run after first logon. ModifyingCommandLine
according to your circumstances, relevant part of anunattend.xml
could look as follows:Please note that in above code snippet the
-NoExit
parameter is removed completely and the-WindowStyle Maximized
is changed to-WindowStyle Hidden
, according to your statement from our previous discussion: "I use the-NoExit
parameter just to be sure if the command fails I can see what happened".