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?

Help
  • 161
  • 1
  • 2
  • 14
  • 2
    In short: Only _PowerShell v7+_ supports `&&` and `||`, the pipeline-chaining operators - see [this answer](https://stackoverflow.com/a/59039112/45375). 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](https://stackoverflow.com/a/41816341/45375) – mklement0 Jun 11 '21 at 15:50

1 Answers1

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.

Santiago Squarzon
  • 41,465
  • 5
  • 14
  • 37
  • 1
    Powershell [supports](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.1) nowadays pipeline chaining operators `&&` and `||`. Those are not the same as a semicolon? – vonPryz Jun 11 '21 at 15:40
  • @vonPryz Yeah I know PS Core supports `&&` and `||` however OP clearly is not using PS Core or hes command would have worked. – Santiago Squarzon Jun 11 '21 at 15:43
  • 1
    Thank you guys!! The recommended parameters work well on my version of PS. – Help Jun 11 '21 at 15:46
  • @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. – Santiago Squarzon Jun 11 '21 at 15:48