Error invoking command to install a Msi through Powershell - 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 ;)

Related

How to use invoke command to install .msi file on remote system which requires elevated permissions

I am trying to run an msiinstaller file on a remote system using the invoke-command.
I have tried a couple of different methods but both have been unsuccessful to this point.
They don't error out but they don't seem to run the install on the remote system either. At least as far as I can tell. Nothing in the event log, still on the old version of software I am trying to update.
I will post both methods here to see if either one of them is close and someone can get me over the top. thanks in advance. [I tend to get confused with how to properly use the invoke command so please cut me some slack if I am totally off base on these attempts.]
common for both:
using get-credential to load up var $cred
var targetHost is the remote system
first method:
$MsiInstallPath = "c:\Temp\MSI\file.msi"
$MsiArguments = " /i `"$MsiInstallPath`" /q SITE_TOKEN='adsfads' "
invoke-command -ComputerName $targetHost -Scriptblock { param($msi_args) Start-Process msciexec.exe -ArgumentList $msi_args } -ArgumentList $MsiArguments
second method:
$scriptblock = { Start-Process msiexec.exe -ArgumentList "/i $MsiInstallPath", "/q", "SITE_TOKEN='abcd'" }
invoke-command -ComputerName $targetHost -Credential $cred -ScriptBlock $scriptblock
Any insight or assistance would be most appreciated.
Thanks
D

Powershell script replace sc config

Good Day,
i look for a same command as
sc config BITS type= own in Powershell.
I think ist with
set-service -name BITS -computername server1234 -idon´t know
I have the problem that my INVOKE-COMMAND don´t work.
But all scripts work only this line don´t work.
Invoke-Command -ComputerName $serverneedhelp -ScriptBlock {Start-Process cmd -ArgumentList "/c 'sc config bits type= own'"}
If anybody can help me, it is were so great.
Thankyou
Greeting
Jan
Run it directly?
Invoke-Command $serverneedhelp { sc config bits type= own }
The other alternative is with wmi: Configure service with Set-Service
in my script work it with
Invoke-Command -ComputerName $serverneedhelp -ScriptBlock {Start-Process cmd -ArgumentList "/c sc config bits type= own"}
But I search a version of Powershell without cmd
I know that this is old thread, but maybe someone would benefit from this.
What worked for me is:
Invoke-Command -ComputerName $serverneedhelp -ScriptBlock {& SC.exe config "bits" type= own}

Can't install chrome remotely through powershell script even when no error is returned

I am trying to install google chrome on a remote server but when I run my script, no error is returned and yet the MSI does not install the software automatically. This script can work locally but not remotely.
Here is the script:
$msi = "MSI path"
Invoke-Command -ComputerName RemoteServer -ScriptBlock {param($msi) Start-Process msiexec.exe -Wait -ArgumentList "/I (MSI Path) /qn /passive"} -ArgumentList $msi
Any help or feedback is appreciated.
I'm not sure, but I think your problem is that you're using the $msi as local and as remote variable. Tow options:
For readonly variables you use the "Using" keyword
See about_remote_variables about details. If you only need to read the value from a variable you can the following:
$msi = "MSI path"
Invoke-Command -ComputerName RemoteServer -ScriptBlock { Start-Process msiexec.exe -Wait -ArgumentList "/I $Using:msi /qn /passive"}
Here you don't need the ArgumentList-parameter of Invoke-Command.
Add a _remote suffix to remote variables
This is only a style I'm using in my scripts to distinguish about local and remote variables.
$msi = "MSI path"
Invoke-Command -ComputerName RemoteServer -ScriptBlock {param($msi_remote) Start-Process msiexec.exe -Wait -ArgumentList "/I $msi_remote /qn /passive"} -ArgumentList $msi
Hope that helps.
Couldnt get my script to work as it is a permission problem on the remote server. It has since been resolved.

Trouble passing parameters to a scriptblock

I am having alot of difficulty passing parameters to a script block in powershell.
$delScript={del C:\DateResults\* $args[0] $args[1] }
$result0 = Invoke-Command -ComputerName $targetServer.TrimStart("\\") -Credential $credentials -ScriptBlock $delScript -ArgumentList #("/q" , "/s")
I am starting to lose the plot trying to please the syntax hell of powershell and it's script block. I have researched this problem to death and I cannot even seem to get this basic problem working. I was hoping after spending the better part of 4hrs on this problem someone on SO could help me.
Thanks in advance!
You are having an issue since you are trying to run a old dos command that PowerShell created an alias for to help ease you into powershell. As mentioned in the comment del is an alias for Remove-Item. Remove-Item only accepts one positional argument which is -Path. To allow your script to work as is you should just be able change your $delScript to this
$delScript={cmd.exe /C del C:\DateResults\* $args[0] $args[1] }
Which would run your code the way you would expect. While I was typing this you already figured out the better approach which is to use the native Remove-Item and remove your -ArgumentList from Invoke-Command
$delScript={Remove-Item C:\DateResults\* -Recurse -Force}
I would also recommend you check Get-Alias to see other so you don't get yourself caught again.
Sorry, it was down to my own ignorance and stupidity. Hovering over 'del' in PowerGUI should have told me everything I needed to know.
Below is all I needed in the end.
$delScript={del C:\DateResults\* -Recurse -Force }
$result0 = Invoke-Command -ComputerName $targetServer.TrimStart("\\") -Credential $credentials -ScriptBlock $delScript

powershell execute .exe remotely

$computername = Read-Host "Enter Machine Name - "
Invoke-command -ComputerName $computername -ScriptBlock { & cmd /c 'c:\download\niniteone\niniteone.exe' /select "malwarebytes"}
Wondering if someone could tell me where I've gone wrong with this, it just dies when I run it. I've put this script together by looking at the others here but I can't seem to get it to work. We use ninite pro to update/install some 3rd party apps and I'm trying to setup some powershell scripts to run it on remote computers. Any help would be appreciated :)
Update - I added the cmd /c to the script block and now it works great!? I read cmd /c isnt needed with powershell v2? I'm confused... It's working but I'd like to get it right.
How about:
Invoke-command -ComputerName $computername -ScriptBlock { Start-Process -FilePath "c:\download\niniteone\niniteone.exe" -ArgumentList "/select `"malwarebytes`""}