1

I'm looking to modify the below script to do two things on an if statement:

if ($PsCmdlet.ParameterSetName -ieq "DumpCreds")
{
    $ExeArgs = "privilege::debug"

}
elseif ($PsCmdlet.ParameterSetName -ieq "DumpCerts")
{
    $ExeArgs = "crypto::cng crypto::capi `"crypto::certificates /export`" `"crypto::certificates /export /systemstore:CERT_SYSTEM_STORE_LOCAL_MACHINE`" exit"
}
else
{
    $ExeArgs = $Command
}`

The line where it reads - $exeargs = "privilege::debug", I need run that and I also need to run - $ExeArgs = "sekurlsa::logonpasswords" The privilege one needs to run first followed by the logonpasswords one.

How do I run 2 commands in 1 if statement in a script?

3
  • You want to assign a value to $ExeArgs twice in one if block? What would that achieve? Commented Nov 18, 2016 at 0:30
  • Yes, well the priv argument is a requirement that needs to be set before I can run the logonpasswords one. Is there a way to do it? Commented Nov 18, 2016 at 1:00
  • $ExeArgs = ' "privilege::debug" "sekurlsa::logonpasswords" '? Commented Nov 18, 2016 at 1:37

1 Answer 1

4

A if statement has no restriction about how much commands you execute in it, so just execute it...

if ($PsCmdlet.ParameterSetName -ieq "DumpCreds")
{
    $ExeArgs = "privilege::debug"
    $ExeArgs = "sekurlsa::logonpasswords"    
}
elseif ($PsCmdlet.ParameterSetName -ieq "DumpCerts")
{
    $ExeArgs = "crypto::cng crypto::capi `"crypto::certificates /export`" `"crypto::certificates /export /systemstore:CERT_SYSTEM_STORE_LOCAL_MACHINE`" exit"
}
else
{
    $ExeArgs = $Command
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.