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?