When using parenthesis in registry name in Get-ACL command used in subprocess in python gives error

230 views Asked by At
ps_cmdlet = r'Get-Acl -Path "HKLM:\SOFTWARE\{ab}" | Format-List'

p = subprocess.call(['powershell', '-Command', '& {'+ps_cmdlet+'}'],shell=True)

I am getting the following error

Get-Acl : Cannot find path 'HKLM:\SOFTWARE\{ab}' because it does not exist.
At line:1 char:4
+ & {Get-Acl -Path "HKLM:\SOFTWARE\{ab}" | Format-List}
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Get-Acl], ItemNotFoundException
    + FullyQualifiedErrorId : GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand
1

There are 1 answers

0
Mathias R. Jessen On

Escape the brackets with backticks:

ps_cmdlet = r'Get-Acl -Path "HKLM:\SOFTWARE\`{ab`}" | Format-List'