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
Post a Comment