Command Prompt or PowerShell "Show what this would do, but don't do it" switch

britechguy

Well-Known Member
Reaction score
4,029
Location
Staunton, VA
I could very easily be conflating what I'm remembering with something available under Unix or one of the Linux variants I've played with.

I could swear that there was a way to run either a single command, or even a BAT file, where you could specify that you be shown what the command(s) would act on if they were run, but that they don't actually run. It was essentially a way to double check yourself that what you believe your code would operate on is actually what it would operate on.

If such exists for Command Prompt and/or PowerShell, would someone refresh my memory? If it doesn't exist at all in Windows, but it rings a bell as working somewhere else, I'd love to know that, too, as I am sure I've done just this in the past. It's just been a lot of years since I was programming day to day and scripting day to day.
 
From a command prompt you can type the command and then /?
For example
dir /?
and it will list all the command options.
 
@14049752

Thanks very much. This appears to be PowerShell centric, and that's very useful. Unless my search mojo is off, this doesn't exist under Command Prompt.

If that's incorrect, can someone point me to the documentation for WHATIF in command prompt?

Just having it in PowerShell may be reason enough for me to slog through learning it more. I find PowerShell syntax almost unbearable.
 
From a command prompt you can type the command and then /?
For example
dir /?
and it will list all the command options.
I don't think that's what @britechguy was looking for. I'm guessing he wanted to be able to string together commands and see what they do in the existing environment without actually running them. This is something I run into all the time in Linux as well as PS. I might find some solution but it's for a different version of PS, MS OS, etc. Sometimes parts of the solution may run while others don't. Then you're left trying to backout of what was done. I'm sure happy @14049752 mentioned that.

@britechguy just dump DOS CLI. I very rarely use it since PS is available on all versions of W10. At least as I know it. I'll leave a shortcut on the task bar in the admin login account.
 
Last edited:
@Markverhyden

I use both Command Prompt and PowerShell. But I doubt I'll ever entirely drop Command Prompt simply because I find the syntax of PowerShell so needlessly verbose and opaque. It feels to me like a reversal of the trend of decades to simplify. Maybe that's because I come out of years of Unix and C programming.

But I definitely need to "brush up on my PowerShell" in any case.

Thanks to @nlinecomputers for the reference recommendation.
 
My experience is CLI command structure is the same in PS. So I only have to learn the new stuff.

Well, many of the old Command Prompt commands have been aliased in PowerShell, and use their old syntax, but then why use PowerShell at all if those are all you intend to use? That's what I keep asking.

There are many parts of PowerShell that are specific to it, so that's the driving force for me. But I am trying to learn PowerShell syntax even for aliased commands simply because it is conceivably possible that, eventually, those might be withdrawn.

But native, as opposed to aliased, commands in PowerShell are, to me, vastly different, more verbose, and more opaque than their Command Prompt equivalents.
 
I only know of the WhatIf for powershell, not anything for command prompt. Some scripts may implement a "dry run" option but i dont know of anything built in.
 
Back
Top