0

Using the command below, I am able to get the value of a group policy setting:

secedit.exe /export /cfg C:\test\secedit.txt && type C:\test\secedit.txt | findstr "SeEnableDelegationPrivilege"

I need to be able to use the same command on PowerShell and I am having issues converting the && statement to work on PowerShell. I tried using this format () -and (), however, that has not worked, does anyone know a way of getting the && statement to work on PS?

1
  • 2
    In short: Only PowerShell v7+ supports && and ||, the pipeline-chaining operators - see this answer. In earlier versions, notably in Windows PowerShell, you can emulate a && b with a; if ($?) { b } and a || b with a; if (-not $?) { b } - see this answer Commented Jun 11, 2021 at 15:50

1 Answer 1

1

If you want to emulate what that command is doing in PowerShell just change the && for a ;:

secedit.exe /export /cfg C:\test\secedit.txt; type C:\test\secedit.txt | findstr "SeEnableDelegationPrivilege"

I would add 1>$null after the first command to avoid the output of The task has completed successfully.....

Edit

I understand ; and && or || are not the same thing in PS 5.1 and below, but is the closest thing I can imagine to emulate what OP is doing.

Other thing he could attempt is:

secedit.exe /export /cfg C:\test\secedit.txt;if($?){type C:\test\secedit.txt | findstr "SeEnableDelegationPrivilege"}

I would link this helpful answer which explains it better than I do.

Sign up to request clarification or add additional context in comments.

4 Comments

Powershell supports nowadays pipeline chaining operators && and ||. Those are not the same as a semicolon?
@vonPryz Yeah I know PS Core supports && and || however OP clearly is not using PS Core or hes command would have worked.
Thank you guys!! The recommended parameters work well on my version of PS.
@Help you probably already have but if not, have a read at the answer I posted in my edit. It explains the PS behaviour better than I do.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.