Missing ')' in method call - Exporting Certs using variable.


running powershell command prompt, success.

dir cert:\currentuser\my | where-object { $_.hasprivatekey -and $_.privatekey.cspkeycontainerinfo.exportable } | foreach-object { [system.io.file]::writeallbytes( "c:\ certs\$($_.thumbprint).pfx" , ($_.export('pfx', 'secret')) ) }

running regular command prompt, failure.

powershell -command dir cert:\currentuser\my "| where-object { $_.hasprivatekey -and $_.privatekey.cspkeycontainerinfo.exportable } | foreach-object { [system.io.file]::writeallbytes( "c:\ certs\$($_.thumbprint).pfx" , ($_.export('pfx', 'secret')) ) }"

which returns following:

missing ')' in method call.

at line:1 char:164

+ dir cert:\currentuser\my | where-object { $_.hasprivatekey -and $_.privatekey

.cspkeycontainerinfo.exportable } | foreach-object { [system.io.file]::writeall

bytes(  <<<< c:\ certs\$($_.thumbprint).pfx , ($_.export('

pfx', 'secret')) ) }

    + categoryinfo          : parsererror: (closeparentoken:tokenid) [], paren

   tcontainserrorrecordexception

    + fullyqualifiederrorid : missingendparenthesisinmethodcall

what missing allow script work within powershell, not regular command prompt?  need run way because executionpolicy set restricted , cannot changed.

hi,

pls try this:

powershell -command "dir cert:\currentuser\my | where-object { $_.hasprivatekey -and $_.privatekey.cspkeycontainerinfo.exportable } | foreach-object { [system.io.file]::writeallbytes( ('c:\certs\'+$_.thumbprint+'.pfx') , ($_.export('pfx', 'secret')) ) }"

rgds,

az



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Generating Event ID 91, 44 with CA (In Event Viewer with source as Certsvc)

Windows server 2012 r2 inplace upgrade failed

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)