Powershell remote get-process works, start-process doesn't - powershell

I'm new to Powershell, so forgive me if this is a basic question. I've enabled psremoting, but for some reason, while
invoke-command -computername MyComputer {get-process}
works,
invoke-command -computername MyComputer {start-process "c:\windows\system32\calc.exe"}
doesn't. I don't get an error message. Rather than the calculator app starting, nothing happens and I get no feedback. Am I missing something?

Related

Invoke-WmiMethod - Quickly fix PsRemoting/WinRM problems (for Invoke-Command usage)

In the event you have computers that are unreachable with Invoke-Command either because WinRm is not running or PsRemoting is disabled here is a good, sure way I've found works everytime, in my environement at least:
$target_comp = "abc1234"
Invoke-WmiMethod -ComputerName $target_comp -Path win32_process -Name create -ArgumentList "powershell.exe -command Enable-PSRemoting -SkipNetworkProfileCheck -Force"
Invoke-WmiMethod -ComputerName $target_comp -Path win32_process -Name create -ArgumentList "powershell.exe -command winrm quickconfig -quiet"
do {
$testpsremoting = invoke-command -computername $target_comp -scriptblock {"test"}
} while (!$testpsremoting)
#REST OF CODE
Explanation :
-Declare variable of your computer name.
-Run the two commands to enable PsRemoting and setup WinRM via Invoke-WmiMethod.
*Since Invoke-WmiMethod returns instantly without WAITING for the commands to actually be done:
-Make a loop that runs until PsRemoting is enabled (until the test Invoke-Command works).
No more Invoke-Command problems! Enjoy and fine tune to your heart's content.
You could use Get-wmi to get the result directly
Get-WmiObject Win32_service -ComputerName $poste | select State,Name,DisplayName
Question changed to provide answer and useful fix for the community.

Powershell Code with No Errors not running

Invoke-Command -cn (Get-Content C:\Users\Administration\Documents\MyText.txt) -scriptblock {Start-Process -FilePath "MyProg.exe" -WorkingDirectory "C:\Program Files\ThisFolder\ThatFolder" -ArgumentList "-1", "-2", "-3"}
Obviously I'm doing something wrong, but not sure what. Anyone seeing something I'm missing?
The process is ending after your session on the remote system is closed. When i run the following test, notepad will run for 5 seconds on the remote computer, then close:
Invoke-Command -ComputerName $RemoteComputer -ScriptBlock {start-process notepad.exe;Start-Sleep -Seconds 5}
If myprog.exe closes on it's own use the -Wait switch to wait for the process to close on it's own. You could also use New-PSSession to keep a session open until you are done then use Remove-PSSession to end the session and have the remote process end.

Powershell remote install/app run

I am going to try and install software remotely onto a server and first i am trying to play around with the invoke-command cmdlet in powerhsell. Below is what I have so far
cls
Exit-PSSession
New-PSSession -ComputerName vm912test
Enter-PSSession -ComputerName vm912test -Credential sceris\pmanca
Invoke-Command -Computername vm912test -ScriptBlock {Start-Process "calc.exe" -wait}
Get-PSSession
However when i run this i see no running tasks in task manager. Does anyone know what i am missing? Once i can get this to work i will expand onto trying to remotely install some software first. I have no issues on communicating with the server and i have remote access/admin access on the box.
I updated with some more code but still receiving the same result that nothing is happening.

Error invoking command to install a Msi through Powershell

I am trying to use PowerShell's Invoke-Command but I am encountering an error that I have no idea of what it is!
Would be great to have some help on this. I am sure that it must be something really simple..
invoke-command -scriptblock{ $executable = "wmic"; & "$executable product call install true","-computername name" ,'path to the msi' }
Thank you!
You could just try using msiexec:
$scriptblock = {Start-Process msiexec.exe -Argumentlist "/i $PathToMSI","/qn"}
invoke-command -scriptblock $scriptblock -computername $name
I´m not sure if you even can install msi´s via wmi, never seen it before. Other than that you mixed up the syntax of your invoke-command a bit ;)

Invoke-Command and Start-Process Issues

I'm trying to execute the following script:
$Cred = Get-Credential
Invoke-Command -Computername Localhost -Cred $Cred -Scriptblock {Start "Notepad.exe" -Wait}
Well, the notepad comes up no problem as Administrator but it is not visible in the current user's account.
I think it's not possible to see gui in an interactive session with different credential, it live in another user session.
Workaround:
start-process notepad.exe -Credential $Cred
I've run into this problem with PS Remoting and could not find a way to get an app running under one set of credentials to show up on the interactive desktop of a different user. I eventually gave up and used SysInternals utility psexec along with its -i parameter.