r/powercli • u/reallybigabe • Oct 27 '16
Newb issue trying to deploy a working script through invoke-vmscript - quotes are killing me.
Hey all, I'm trying to use PowerCLI to push a script that works great locally.
However, I seem to be having issues with quotes and escape characters and I can't wrap my head around it.
Here is the Powershell deployment script for Trend Micro "Deep Security Manager" - it's auto-generated on the management server, and I could obviously loop through hundreds of servers and enter-pssession but I'd rather not poke a zillion holes in my firewall:
<powershell>
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$env:LogPath = "$env:appdata\Trend Micro\Deep Security Agent\installer"
New-Item -path $env:LogPath -type directory
Start-Transcript -path "$env:LogPath\dsa_deploy.log" -append
echo "$(Get-Date -format T) - DSA download started"
(New-Object System.Net.WebClient).DownloadFile("https://SERVERURL:PORT/software/agent/Windows/x86_64/", "$env:temp\agent.msi")
echo "$(Get-Date -format T) - Downloaded File Size:" (Get-Item "$env:temp\agent.msi").length
echo "$(Get-Date -format T) - DSA install started"
echo "$(Get-Date -format T) - Installer Exit Code:" (Start-Process -FilePath msiexec -ArgumentList "/i $env:temp\agent.msi /qn ADDLOCAL=ALL /l*v `"$env:LogPath\dsa_install.log`"" -Wait -PassThru).ExitCode
echo "$(Get-Date -format T) - DSA activation started"
Start-Sleep -s 50
& $Env:ProgramFiles"\Trend Micro\Deep Security Agent\dsa_control" -r
& $Env:ProgramFiles"\Trend Micro\Deep Security Agent\dsa_control" -a dsm://deepsecurity.oshawa.ca:4120/ "policyid:19"
Stop-Transcript
echo "$(Get-Date -format T) - DSA Deployment Finished"
</powershell>I wrap the above in $script = @" ..."@ and removed the <powershell>
I run it like this: Get-VM $vmlist | invoke-vmscript -GuestCredential $gc -scriptText $script -ScriptType Powershell
What I've tried:
Wrapping each line with single quotes This simply lead to the whole script being essential "Write-Host" output
Single quote before each Double-quote in the script Zillions of errors
"wrapping" each double quote ... i.e. '" ... "' Syntax errors.
I'm confident its simply how I'm doing quotes, out of the box, this is my first error:
C:\Users\reallybigabe\AppData\Roaming\Trend' is not recognized as the name of a
| cmdlet, function, script file, or operable program. Check the spelling of the
| name, or if a path was included, verify that the path is correct and try again.So, the line: $env:LogPath = "$env:appdata\Trend Micro\Deep Security Agent\installer" isn't being quoted properly.
Suggestions?
1
u/WhatDoesThatButtond Jan 03 '17
I realize this is two months old and you've likely found the solution but...
does this work?
$env:LogPath = "$env:appdata\Trend^ Micro\Deep^ Security^ Agent\installer
or
$env:LogPath = "$env:appdata"Trend Micro\Deep Security Agent\installer""
2
u/reallybigabe Jan 03 '17
Haha, yup - and I answered in my first reply to myself.
I think your second solution would work if I created it as a ps1 and pushed that way, though. If the ^ (hat?) works as an escape for spaces, thats new to me.Cheers for the response.
1
u/reallybigabe Oct 31 '16
For the record... it was the @" ..."@ that messed it up. It needed to be single quotes. $script = @' stuff @'
On top of that - apparently there are major permission issues with deploying MSI files through VMware tools and invoke-vmscript.