Can anyone provide any insight on how to make this work?
$ADSession = New-PSSession -ComputerName $ComputerName -Credential $DomainAdminCred
$Script = "Start-Process -FilePath M:\Setup.exe -Wait -Verb RunAs -ArgumentList '/Q /ConfigurationFile=C:\SQLConfigurationFile.ini'"
Invoke-Command -Session $ADSession -ScriptBlock {$Script} -Verbose
The invoke-command immediately returns, and SQL is not installed.
If I run the same Start-Process locally, it will run (with a UAC prompt).
You have 1. quotes around your command sequence, rendering it just string data, and 2. scriptblock around that. If you execute the scriptblock you’re passing to -ScriptBlock
parameter with & {$Script}
you’ll see it just outputs the string to the console. That’s exactly what’s happening on the remote machine.
Replace your quotes in the $Script =
definition line with the braces you’re using in the Invoke-Command
line and drop the braces from that line:
$Script = { Start-Process -FilePath M:\Setup.exe -Wait -Verb RunAs -ArgumentList '/Q /ConfigurationFile=C:\SQLConfigurationFile.ini' }
Invoke-Command -Session $ADSession -ScriptBlock $Script -Verbose
This doesn’t work?
Invoke-Command -Session $ADSession { M:\Setup.exe /Q /ConfigurationFile=C:\SQLConfigurationFile.ini }
[quote quote=160010]Can anyone provide any insight on how to make this work?
$ADSession = New-PSSession -ComputerName $ComputerName -Credential $DomainAdminCred
$Script = "Start-Process -FilePath M:\Setup.exe -Wait -Verb RunAs -ArgumentList '/Q /ConfigurationFile=C:\SQLConfigurationFile.ini'"
Invoke-Command -Session $ADSession -ScriptBlock {$Script} -Verbose
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The invoke-command immediately returns, and SQL is not installed.
If I run the same Start-Process locally, it will run (with a UAC prompt).
[/quote]
The first problem I see is that you define $script locally, but the invoke-command has no way of knowing what $script means.
You can pass that as $using:script inside the scriptblock.
I had to do something similar (sorta kinda…) I ended up doing this:
$arglist="/quiet /log log.txt"
foreach ($s in $servers){
$session=New-PSSession -cn $S
if (!(test-path \\$S\G$\core)){copy-item -ToSession $session -path G:\core -destination G:\core -force -recurse}
invoke-command -session $Session -Scriptblock {
set-location G:\core
start-process -filepath dotnet-hosting-2.2.3-win.exe -ArgumentList $using:ArgList -wait
}
}
without the -wait, control will pass back to the command line. If the session were to end, then the install won’t finish. I wish I wasn’t speaking from experience. What I needed was much simpler than what you’re doing, I’m not sure if the UAC will cause the remote install to hang or not.
I tried this - same result.
Invoke-Command -Session $ADSession -ScriptBlock {Start-Process -FilePath M:\Setup.exe -Wait -Verb RunAs -ArgumentList '/Q /ConfigurationFile=C:\SQLConfigurationFile.ini'} -Verbose
I believe the issue has to do with the SQL installation EXE itself. When I run it locally, it does pop open another window when it runs. I’m guessing that it can’t do that when using invoke-command, or at least not the way I’m doing it.
Uh, when you want to wait for a command to end with start -wait, you get into quoting issues. Makes me go back to start /wait in .bat files sometimes.