Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Run multiple commands using CMD with PowerShell.exe -command

$
0
0

I am trying to create a PowerShell command that reads a registy variable and then executes a command.

It does this from the CMD command line. And the script runs under SYSTEM.

I have the following code:

powershell.exe -ExecutionPolicy ByPass -WindowStyle Minimized -Command "$ErrorActionPreference = 'silentlycontinue' | New-Variable -name UserNameForSapFolderRemoval -Value (get-itemproperty 'HKCU:\Volatile Environment' | Select-Object -ExpandProperty UserName) | Remove-Item $("C:\Users\"+$UserNameForSapFolderRemoval +"\AppData\Roaming\Microsoft\WindowsStart Menu\Programs\Sapgui 7.30") -Force -Recurse | Remove-Variable -Name  UserNameForSapFolderRemoval"

But it returns with:

The string is missing the terminator

I added the " character but without succes.

Any idea how I can get this powershell command to run succesful?



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>