Reputation: 143
I have this command below that uses the WMI and Win32_process to run a command on a remote computer.The computer is called 7-df-1 in the example below.
I am having an issue with my quotes I have tried single and double quotes but the command still doesn't work. It's supposed to download a Surface firmware installer to the C drive on the remote computer.
What am I doing wrong? Thanks for looking into this
([WMICLASS]"\\7-df-1\Root\CIMV2:Win32_Process").create(“ (new-object system.net.webclient).downloadfile('https://download.microsoft.com/download/6/A/C/6ACB37C4-E4C1-4E0E-BBAE-AC7A0C303593/SurfacePro4_Win10_15063_1701801_0.msi', 'c:\save.msi')”)
Upvotes: 0
Views: 1173
Reputation: 3063
Create() method accepts commandline as string, so if you simply give a PowerShell cmdlets/expression it won't recognize.
So you have to mention the handler for the particular commanline you give.
([WMICLASS]"\\localhost\Root\CIMV2:Win32_Process").create(“Powershell.exe -c &{ (new-object system.net.webclient).downloadfile('https://download.microsoft.com/download/6/A/C/6ACB37C4-E4C1-4E0E-BBAE-AC7A0C303593/SurfacePro4_Win10_15063_1701801_0.msi', 'c:\save.msi')}”)
You can get help infor for Create() method for Win32_Process here
Upvotes: 1
Reputation: 328
Bad answer. See comments section.
I agree with @NullUserException, Invoke-Command is the cmdlet to be using for this. I advise you try it.
With that said, I can't test your command in my environment but it looks like you're trying to pass a literal command to the remote machine as a string. In that case you want to use HereStrings. They are the step above single quotes. Try this:
([WMICLASS]"\\7-df-1\Root\CIMV2:Win32_Process").create(@' (new-object system.net.webclient).downloadfile('https://download.microsoft.com/download/6/A/C/6ACB37C4-E4C1-4E0E-BBAE-AC7A0C303593/SurfacePro4_Win10_15063_1701801_0.msi', 'c:\save.msi') '@)
Upvotes: 0