Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to/how do you stop powershell using certain cmdlets?

Tags:

powershell

cmd

Powershell is clearly a lot better than cmd but it hides basic functionality. I normally use it to figure out how to use commands that I want in scripts but it breaks a large number of basic things and I end up using both side by side if I hit a sticky spot.

Today this was removing a directory - rd or rmdir - both of which are broken in powershell in favour of one it's undocumented (from the commandline) cmdlets Remove-Item. I seem to run into it all the time though - sc (for mucking around with services); where for finding what program is being called when you type a command etc etc.

Hilariously I actually got the problem with sc and then googled to find out the command where only to discover that didnt work in powershell either! That was a confusing day

In some cases once you know this is what's going on you can type the full exe name (for instance 'where.exe' will work whereas 'where' on its own wont).

This isn't the case with rmdir however. Although interestingly typing 'where rmdir' in cmd doesnt work.

So... my question is this - Is there a way of turning off (preferably all) cmdlets in powershell and just getting the normal stuff instead?

like image 376
JonnyRaa Avatar asked Jul 15 '26 14:07

JonnyRaa


1 Answers

There is no need to turn off cmdlets in powershell as that would destroy the very reason for having it.

Most of the "normal" stuff is there anyway, which you can find by using the get-alias command.

C:\> get-alias

CommandType     Name
-----------     ----
Alias           % -> ForEach-Object
Alias           ? -> Where-Object
Alias           ?? -> Invoke-NullCoalescing
Alias           ac -> Add-Content
Alias           asnp -> Add-PSSnapin
Alias           cat -> Get-Content
Alias           cd -> Set-Location
Alias           chdir -> Set-Location
.....
..... AND A WHOLE LOT MORE!

If you are missing a command that you really, really want to have, then you can easily add a new alias:

Set-Alias python2 "C:\Python27\python.exe"

In order to avoid having to do this every single time, you can simply add this into your startup profile. Just type in $PROFILE into the command prompt and it will show you the file path. If it doesn't exist, simply create it, and any powershell commands you add to the top will be automatically invoked when you start a new session.

And last thing. All of the commands are documented, and you can get to them easily using just two.

Just type this into your command prompt and you will be on your way to Powershell enlightenment!

get-help get-command

get-command -noun Item
get-command -verb get
like image 157
Josh Avatar answered Jul 17 '26 16:07

Josh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!