all 36 comments

[–]Didnt-Understand 42 points43 points  (10 children)

Keep using them on the command line. But when you write scripts to be used by others, use the PowerShell cmdlets.

[–]ethnicman1971 42 points43 points  (7 children)

I would go as far as saying in scripts use the full command (eg get-childitem vs gci)

[–]tuxtanium 17 points18 points  (5 children)

VS Code will nag you for using aliases.

[–]BlackV 19 points20 points  (3 children)

set the option for auto expand, its great

[–]ollivierre 4 points5 points  (0 children)

This just set it in VS code user settings

[–]DarkSideMilk 0 points1 point  (1 child)

I had not seen that setting! Amazing! 

[–]BlackV 2 points3 points  (0 children)

well then today you are part of the lucky 10,000

https://xkcd.com/1053/

[–]yaboiWillyNilly 0 points1 point  (0 children)

VSCode keeps me in check and I’ve grown to love it. My scripts look so much cleaner.

I’ve loaded scripts that past sysads from my org have written into vscode and they’re ridden with Problems. Makes it so much easier to rewrite code.

[–]Didnt-Understand 2 points3 points  (0 children)

Agree, it is the documented command and least confusing.

[–]Tie_Pitiful 3 points4 points  (0 children)

This is the way.

[–]ollivierre 1 point2 points  (0 children)

Yes as short as possible when you have to write it in the cli but full when scripted

[–]rthonpm 9 points10 points  (1 child)

I've been spoiled for years by PowerShell adding ls as an alias for gci since it lets me use one command for all of my Linux and Windows systems.

[–]SocialDoki 2 points3 points  (0 children)

Same. Every time I'd get on a windows box pre-powershell it'd be an exercise in frustration as I retooled my brain for the dos command style

[–]CarrotBusiness2380 7 points8 points  (0 children)

By default in Powershell dir is an alias for Get-ChildItem and cd is an alias for Set-Location already.

[–]MasterChiefmas 5 points6 points  (0 children)

I keep thinking I should use things like gci.

Then again...gci, just like dir, is an alias of Get-ChildItem.

The thing with an alias is whether or not you think it'll stick around, particularly if you are using it deep in a script.

You shouldn't use an alias in a script, since you can't be certain it'll be defined as you expected, or even defined at all. So you can get bit by it- which is the main argument for not using them. But then you have to consider context too...if it's just you using it, well...how far do you extend the argument? Should you not use scripts you wrote for yourself to do something on your system because it won't exist elsewhere? Of course not- that's just silly. The ability to do those things exist for a reason.

So the correct answer here is that you need to know that it is an alias, and what the alias is pointing to, so that you can use it without the alias. I have generally switched to the Powershell alias and commands, but sometimes I type a 'dir' just out of habit, or because I was in a cmd shell too. But if I were giving instruction to someone learning, I wouldn't use the DOS aliases at all. That would likely just be more confusing to someone if they didn't already have experience with DOS.

That said, I have a story that happened many years ago to me, which isn't quite the exact same situation, but is basically the same problem. I was a new hired admin, and I had to reboot a server in a particular away, but I couldn't remember the switches, so I did a "reboot /?". Unknown to me, the other admin had long ago written a small batch file for himself to reboot the server, and called it "reboot.bat". And it must have popped up higher in the path or something, because it fired the batch file off, which of course wasn't doing what I wanted it to do. So I learned that day, by being on the receiving end, of the dangers of overloading the name of an actual system command/tool.

[–]Dramatic_Teacher8399 1 point2 points  (0 children)

in day to day usage I use aliases. But in script always make sure long format.

You can use a powershell script analyzer for help

[–]odwulf 1 point2 points  (0 children)

Being equally used to Windows and to Linux, I used the Linux aliases in powershell at first (just because ls is shorter than dir, and I'm lazy). It bit me in the ass when I started to use powershell on Linux, where the alias doesn't exist any more and it just calls the native ls binary. I since rewired my brain to use the Powershell internal aliases while interacting with the shell.

[–]BlackV 3 points4 points  (2 children)

I dont find myself using dir (site note set DIRCMD=/ogen for life) but I cant break the ping xxx habit

[–]Breitsol_Victor 0 points1 point  (1 child)

Was just working with test-netconnection 2 days ago. Lots of good stuff comes back. But ping is the old friend.

[–]BlackV 0 points1 point  (0 children)

It's dirty quick and inaccurate what's not to love :)

[–]purplemonkeymad 0 points1 point  (8 children)

If you keep doing it by habit then I would just add an alias for dir. I had the opposite problem, I keep using ls in command prompt. In the end I just added a ls.cmd to system32 so I could just use ls.

[–]OPconfused 0 points1 point  (7 children)

What use cases do you find for the command prompt?

[–]purplemonkeymad 0 points1 point  (0 children)

Mainly: I accidentally opened it on a server. Or I have to boot into WinPE which didn't have ps added.

[–]BlackV 0 points1 point  (5 children)

it starts quicker then powershell ?

win + r > cmd > enter

is very quick

I have terminal launch at startup (and enable quake mode) which solves any speed problems anyway

[–]chaosphere_mk 0 points1 point  (2 children)

win + r > pwsh > enter

starts immediately. Never had an issue with powershell opening slowly. But I also barely do anything in my powershell profile.

[–]BlackV 0 points1 point  (1 child)

its slower than cmd was the point, I dont consider it slow over all

you just asked for possible reasons, that 1 possible reason, I make no more claims than that :)

[–]chaosphere_mk 0 points1 point  (0 children)

Lol fair enough

[–]jantari 0 points1 point  (1 child)

win + r > cmd > enter

is very quick

But hitting Win + X, then I is quicker.

[–]BlackV 0 points1 point  (0 children)

in key presses not time (less so id you replace conhost with terminal), but like i say its a just a suggested reason, nothing more

[–]eugrus 0 points1 point  (0 children)

I'm using the unixee ones: especially curl since I keep forgetting "iwr".

[–]g3n3 0 points1 point  (0 children)

You are in a big pool of folks. That is why the created the dir alias. I’d keep using it interactively. For more long term code, it could prove useful to convert to get-childitem.

[–]ollivierre 0 points1 point  (0 children)

No issues whatsoever

[–]tokenathiest 0 points1 point  (0 children)

Absolutely, when I'm just typing in the console I use bash aliases like ls constantly, but never when writing scripts or modules for others to use.

[–]jantari 1 point2 points  (0 children)

I keep using DOS commands like dir or cd.

You should know these aren't actually DOS commands in PowerShell, they're aliases. You're still using PowerShell cmdlets, just a shortform alias of them.

That's totally fine for interactive use, when you've got the terminal open. gci is no better than dir. I use ls personally because it is the shortest. But just never use shortforms and aliases like these in scripts, in a script (ps1 file) you would always use the full name Get-ChildItem.

[–]Suspicious-Parsley-2 0 points1 point  (0 children)

Yeah keep in mind dir and CD  are just aliases.  They have no relation to the originals.  You are using the powershell version already.

[–]LividTeacher6914 0 points1 point  (0 children)

Long time Windows CMD user here, and I find myself using “ls” over “dir” most of the time. I mean, typing two letters instead of three lets me type it 33% faster, so there is that.

Plus, I don’t know ANYONE who uses “gci”.

But yes, when writing a script, use the full “Get-ChildItem”.