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?
powershell -?
: To write a string that runs a Windows PowerShell command, use the format:"& {<command>}"
<
and>
(or Less-Than Sign and Greater-Than Sign) here are metasymbols, not a part of resultant code. Hence, you can use something like the following:… -Command "& {Start-Sleep 30; Get-Childitem .}"
."& {Get-Childitem -Path C:\}"
works fine, but"& {New-SmbMapping -LocalPath z: -RemotePath \\10.10.10.5\Share; z:\script.ps1}"
doesn't even display a PowerShell console at all..."& {New-SmbMapping -LocalPath z: -RemotePath \\10.10.10.5\Share -UserName User -Password password}"
worsk fine. However,"& {New-SmbMapping -LocalPath z: -RemotePath \\10.10.10.5\Share -Persistent $false -UserName User -Password password}"
does not open any PowerShell window. Maybe the $ sign is the problem here... Trying some more dichotomy...