What I Hate About PowerShell
With all the love PowerShell is getting these days one might think that the golden age of (Windows) scripting has finally begun. Maybe it has. But one man’s nirvana can be another man’s hell.
My Background
I started with programming at the age of 14 by learning GFA Basic on the Atari ST. After devouring the Kernighan and Ritchie book I quickly switched to C and I must say that understanding pointers at an early age really helps in later life!
After a 10 year hiatus I returned my attentions to the world of computing, learning (and loving!) Perl which I mainly used for systems management and migration tasks. I wrote tools like SetACL (in C++), dabbled in Visual Basic (at the time not based on .NET yet), dived into the arcane syntax of Windows batch files and picked up regular expressions along the way. Later I wrote a couple of tools in C# and VB.NET (based on the .NET framwork), e.g. SetACL Studio. For my latest product, uberAgent, I went back to C++.
I am mentioning all of this so that when you decide that I am an idiot after reading this article you at least give me credit for being an idiot who has seen a bit of the programming world.
From Monad to PowerShell
I heard about PowerShell first when it was still called Monad. At the time I was thrilled by the prospect of having a powerful scripting language for Windows. I was hoping for something like VBScript turned good or Perl being included in the default install of Windows. My enthusiasm was such that I wrote a paper explaining PowerShell and presented it to colleagues and customers.
However, over time my enthusiasm waned. I found more and more quirks in the language that made life unnecessarily difficult. Certain things that should be simple and intuitive are not. Perl’s slogan Easy things should be easy and hard things should be possible does not apply to PowerShell.
The remainder of this post is a list of things that, in my humble opinion, are wrong with PowerShell. Some of the points may be subjective. I might be wrong about a thing or two (in which case please correct me by commenting and I will fix the error). You have been warned.
Syntax
Operators
PowerShell’s operators are horrible. E.g. testing strings for equality:
"abc" -eq "abc"
Instead that should be something like:
"abc" == "abc"
The same applies to most other operators. E.g. comparing two numbers:
8 -gt 6
Instead of:
8 > 6
Escape Character
Having the backtick as escape character is just plain weird. Chances are if you have used other programming languages the backslash feels much more natural.
"Let's print line one`nand line two`n and a quote `""
Instead of:
"Let's print line one\nand line two\n and a quote \""
If Requires Curly Brackets
Many languages let you do away with the curly brackets if you have only a single statement in an if. Not so PowerShell. Instead of this:
if (5 -gt 3)
"hello"
You need to write this:
if (5 -gt 3)
{
"hello"
}
Function Definitions
Functions can only be used after they have been defined. This leads to constructions like this one where the script effectively starts at the end:
function main
{
# do stuff
}
# Call main
main
Function Calls
PowerShell functions are called without parentheses, but .NET functions are called with parentheses.
E.g. calling a self-defined PowerShell function LogMessage:
LogMessage "Here's a message"
Versus calling a .NET function
[string]::IsNullOrEmpty($configFile)
Script Syntax Check
Scripts cannot be syntax-checked before they are run. If you have a syntax error in a code branch that is not executed during testing you might only find out about it after the script has been deployed to production machines.
E.g. PowerShell happily executes the following code without the slightest warning:
Set-StrictMode -Version 2
$variable = 10
if ($variable -eq 30)
{
aslkfjlsjdf # It probably should complain about this
}
Lack of Mandatory Variable Declarations
This (along with the next point) is by far the worst I have found while working with PowerShell.
If you want to write production-quality code you need a way to force the language to force you to declare variables before they are used. Perl has its use strict, heck, even VBScript has option explicit. Only PowerShell has nothing.
Take a look at the following code. You expect it to print “20”, but because of a stupid typo it prints “10”:
Set-StrictMode -Version 2
$variable = 10
# other code
$varable = 20 # Notice the typo
# print value
$variable
There is a Connect item on this.
Scope of Variables
This is where it gets really funky.
PowerShell uses dynamic scoping with copy on write (versus lexical scoping, which is what everybody else uses). If you have used other languages before this is totally confusing. Even if you have not this easily leads to errors that are really hard to find.
So what is this about? When a new scope is created (basically whenever you declare a function), all variables from the parent scope are copied into the new child scope. Notice the word copied. That means you now have two variables of the same name. When using the variable name in the child scope the child scope’s copy of the variable is changed. Once you leave that scope the change is gone – the parent scope’s copy of the variable remains unchanged.
Take a look at this script:
Set-StrictMode -Version 2
function ChangeVariable()
{
$variable = 20
# Print the value from inside the function
"Value from INSIDE the function: " + $variable
}
# Set initial value
$variable = 10
# Print the value
"Value from OUTSIDE the function: " + $variable
# Call the function that supposedly changes the variable's value
ChangeVariable
# Print the value again
"Value from OUTSIDE the function: " + $variable
The value of $variable is printed three times. You might naively assume that the output is “10” followed by “20” and another “20”. Not quite:
Value from OUTSIDE the function: 10
Value from INSIDE the function: 20
Value from OUTSIDE the function: 10
Here is a nice blog post explaining this in more detail.
69 Comments
So a language designed to get admins scripting makes someone from a dev background pissy because it doesn’t conform to a bunch of developer expectations? Did you ever consider the reason that admins avoided scripting was because of all the Dev bullshit that went into it?
Not agree with you Narkor. PowerShell isn’t easier than any other scripting language.
Dev bullshit as you named it, could prevent from typos for example. The way the syntax is controlled is just inefficient…
Some customers want to use PS script as logon script and ask why logon times increase…
Vbscript still has some bright years ahead of it ;)
I agree and disagree with each of you on this. First, Powershell is not used by many admins at this time. I find that approximately 10% use it a lot, 50% have used it for one or two specific tasks, and 40% have not used it at all. Powershell is NOT easy and really does take a developer background to understand and use. Powershell is not efficient, takes many iterations to test and perfect, and provides little to no feedback as to what is being changed or the final outcome of the command/cmdlet. I find that many want to use Powershell for tasks that are already being accomplished by other features/products (Legrand example with Vbscript in login script), which is often a mistake. Powershell is powerful and awesome, but must be understood better, marketed better by Microsoft, and more use cases created so that it is easier to “consume” by the average administrator.
Agreed. I have programmed in 100’s of procedural/scripting and oo languages in the last 35 years and Powershell was not well thought out in regards to scope. The fact that functions() have not concept of local scope blows me away. Seems like the designers hoped that all logic would be isolated into separate ps1 files and command-lets. Have a funny feeling that this product was conceived of by either a newbie programmer at MS or by a “over seas” affiliate. Anyway, MS Powershell is just one more reason why MS can’t survive the long haul.
Time will show, who survives :-)
Also don’t agree. I develop in four different languages not including Transact-SQL which of course isn’t a “programming language” per se but still must be learned, and I also am a sysadmin and DevOps guy. I can’t stand PowerShell. It doesn’t make any sense, is far too wordy and full of arcane looking syntax, blows it completely on many MANY AWS aimed scripts, and has far too many hard to find modules and cmdlets to figure out where things are. That last part is due entirely to the leviathan that is Windows base code. But either way, I am seriously trying to find a way to feel completely confident writing in IronPython to do what I am evidently forced to to in PowerShell. Because I don’t get how to retain it and I don’t really want to try.
This did not age well.
Lol I randomly came across this post and you summarized my thoughts exactly ^
Been tasked with writing my first Powershell script. As with nearly all newbie written software of tye last 15 years its been cobbled together with Google/Stackoverflow searches.
I have over 35 years experience in a variety of languages, bash being my scripting language of choice (even on windows via Cygwin … works remarkably well).
I found it fairly easy to build a working script following the of “how would i do this in bash?” and finding the Powershell equivalent for practically each line.
I was surprised at our wordy it was, which made it seem long winded. Add-Content -Path ……. surprised me. Backticks for escape look silly as its a character like quotes you expect to balance out in a piece of code.
I’m not a fan of Python because I find if I have to move blocks around it entails more changes to indent everything correctly again. But I find Python has a consistent syntax and look, whereas Powershell code has a ‘mongrel’ like disposition.
However, with the aid of Google/Stackoverflow I was able to get what I needed working fairly quickly.
I did get puzzled by why ‘==’ weren’t working in my ifs but once I learned -eq etc was what it expected that was OK.
I also disagree. I am much more of an “admin” than I am a developer — though I do admit I have a formal programming/development background.
As an admin and infrastructure engineer, I’ve scripted is just about everything out there through the years. I never HATED a scripting language before I met Powershell. It’s problems are not just “developer issues”. It is fundamentally broken, flawed, inconsistent, buggy, and just plain backwards.
It was not made to get admins scripting (sorry if this offends, but solid admins have always been scripting). It was made to fill a perceived gap, but clearly made with virtually no architectural forethought or syntactical clarity.
Sorry, Narkor, but I also must strongly disagree with you.
As for my background, I am a Sr Cloud Engineer and certified Azure Architect Professional. I do have a Computer Science and Engineering Technology degree, as well as formal development experience. But honestly have been in the IT infrastructure world much longer than development (though as a Cloud Engineer that distinction is very much blurred). I was the “Admin” you want to reference for more years than I care to remember.
All of those “dev rules” you are pissing on exist for a reason. The reason is to make languages (be it scripting or high level development languages) understandable and usable. They are there to make things work. Unfortunately, a new breed of people came along with cowboy mentality and abandoned the discipline that makes Computer Science “science”. Powershell is a prime example of this hacking mentality with little (if any) thought to a solid and workable language. Ergo the reason Powershell has been reinvented so many times, and so full of bugs.
Not only is Powershell pure crap for all the reasons pointed out in this article and more — its documentation is a big pile of stinking dung too! This makes Powershell even worse, since it is not possible to simply go to a documentation page for good information on exactly what a command does and how it works.
Maybe the microsoft documentation is a big pile of stinking dung, but at least it works.
You want to know, what a specific Cmdlet (example: get-chiliditem) is doing?
Get-Help Get-Childitem -online
BAM – You get a website in your language which is explaining the Cmdlet you’re interested in with all possible parameters and it’s providing examples.
My biggest problem with powershell and windows is that it is up to each application creator to provide powershell snapins modules or other functions.
I always hear Jeffrey Snover talk about Linux having config files being a much easier solution than dealing with an api for everything. While the api approach seems nice, versus grep, awk sed and others it just falls down at every edge case. Why cant dns servers just be in resolve.conf? DSC aims to wrap a lot of this but it is just cake icing with the same underlying powershell limitations.
It is just crazy how to config every thing on windows require a different cmdlet. Then if you want to do sonething that doesnt have a cmdlet like changing the binding order of adapters it is a massive bunkerbuster. Then think about all the apps that have nothing. Its a random registry hunting expedition. Try changing a Hkey user for everyone? Loading ntuser.dat… ugh
As for your complaints above…eh. annoyances and gripes… What I have found assisting and maintaining the chocolatey project is that the language falls down on large code bases. You end up with so much nuance and code jerking around that just is managed nicely with modules classes and methods or gems in other languages like ruby.
Dont even get me started on parameter and switch handling if you want complex options. Its obtuse and constraining. Environment variables and refreshing them? Its so busted.
Lastly, cmd.exe is the worst thing about powershell. The borked intertwining of behaviors can make anyone go batty ;)
Yes, configs are great, I admit. But scriptable configuration objects are cooler and more modern. Come out of C and Unix time finally and Think OO!
@Helge: Nice post.
Hi, nice article. As I started with PowerShell, I need to say that I really hated it and didn’t know what is so good at it. After a while, now I really spend up to 50% with PowherShell and think it is a great stuff.
I need to say, I’m not a programmer and never was and never want be. No defense. I’m speaking from the Admin site, mostly System Center.
Why I’m hated it is easy, PowerShell felt for me in the first look like a new program language, with so many stupid thinks like described in the article here. It also really confused me that you had to write first the function before you can call it (what obviously make sense). But anyway.
What has changed and why I spend so many time with Powershell now? Easy as well. I see PowerShell not as a programming language and it isn’t really one. PowerShell is the next generation of Command line. And in this case it is a great next version of it. For me as an administrator it is a great tool to quick script something. Of course not multiple pages of code, but you haven’t done this with command line either, right? It is to script quick automatism and not to write new programs. To make daily task more easier.
So for me is PowerShell a good thing, even with the small issues mentioned above. It is for daily quick requests and tasks and to script short automatism. If I would need to write a more complex program I would go with C# maybe, but not with PowerShell.
Have done quite some development in assembler, C, C++, Delphi etc. in my days and I can understand your gripes with Powershell as a programming language. But since I now days mainly do windows infrastructure management I think you’ll have to view Powershell in a different light. It is more of a windows version of bash than an alternative programing language. You can do stuff with Powershell that I wouldn’t dare to imagine the loops you had to jump thru to get bash doing the same thing.
@ rich siegel. If you end up supporting massive amounts of code I Powershell I think your design is fundamentally flawed. Powershell is glue. Not bulk code. That should be commandlets implemented in c# or whatever. :-)
Excellent article. PSH V4 Set-StrictMode -Version Latest will catch undefined variables, as well as undefined properties. I want the former, but cannot suppress the latter.
The metacharacter escaping issue is even more complicated. With -split, -match and -replace, it uses backwhack metacharacters. With $string.Split() it uses backtick metacharacters.
My two biggest issues are:
– Performance can use work. It is very resource intensive compared to Perl on a *nix platform.
– Lack of support in VisualStudio. PowerShell_ise.exe is nice, but not powerful enough. VS has hooks to *use PSH* for build automation, but no IDE support.
PowerGUI is not being developed any longer and is hard to find, but it is still a much more powerful IDE than ISE.
VS has PowerShell support.
https://marketplace.visualstudio.com/items?itemName=AdamRDriscoll.PowerShellToolsforVisualStudio2017-18561
– Sincerely the guy that implemented the VS PowerShell support ;)
Hi Helge,
Let’s start by stating that I’m obviously biased on the subject ;-)
You make some valid points, but some enter the nitpicking area IMHO. No language is perfect (as no OS is perfect), but in this case I think the most important criterium is what admins in the Windows world can do better, faster and easier thanks to PS.
If you look at the Monad paper, where it all started, I admire how the PowerShell team was able to implement their vision in a corporate giant like Microsoft.
Like I said earlier, nothing is perfect, but let’s not throw away the baby with the water.
And I’m pretty sure some of your valid comments will make it to the PS team.
Hi Helge!
Good stuff. I’m assuming you know most of these, but a few thoughts:
Operators – It sounds like this was a tough decision for the PS team. How do you merge features from shell and scripting languages without conflicts? If they went with > as an example, you would have similar complaints on the shell side for the lack of consistency with standard redirection operators.
Escape character – Agree to an extent. That being said, we’re talking a Windows environment. From convenience perspective alone, \ would likely turn off the vast majority of admins. Can you imagine if every single path had to use C:\\Better\\Not\\Miss\\An\Escape\\Character syntax? Ouch!
Curly brackets – yeah, that functionality would be handy.
Function definitions, Script Syntax Check – If you don’t want a quirky language that behaves one way when at the shell, another way when scripting (even if the quirks are ever so slight), this seems like the best approach. That being said, I’m not a developer and this is over my head : )
Function calls – This seems aimed at making PowerShell appear more like a scripting language than a low level language. I don’t mind the more formal syntax, but many, many administrators out there would struggle and potentially give up the language if it forced that syntax.
Lack of Mandatory Variable Declarations – Agreed.
Scope of variables – Agreed to a certain extent. I’m assuming this decision was to make the lives of admins easier, who may be less familiar with scope (who would still likely be confused by dynamic scoping…)
Ultimately, I think the first paragraph of Microsoft’s TechNet article on PowerShell explains this… Windows PowerShell® is a task-based command-line shell and scripting language designed especially for system administration. Built on the .NET Framework, Windows PowerShell helps IT professionals and power users control and automate the administration of the Windows operating system and applications that run on Windows.
Cheers!
Helge
Thank you so much for taking the time to write up the things you don’t like about PowerShell in such a clear and coherent way. The PowerShell team considers information like this pure gold.
> I am mentioning all of this so that when you decide that I am an idiot after reading this article you at least give me credit for being an idiot who has seen a bit of the programming world.
Absolutely not! Many of the things you articulate here are things we struggled with/are struggling with. For instance, the biggest on this list is the operators. You won’t find anyone on the PS team that disagrees with you here. This is an area that goes against my explicit goal to be as closely aligned with C# as possible. The issue is that our highest priority was to be a tool for admins and to support the admin development model – interactive shell -> simple scripting -> production scripting -> systems programming. The need to be both interactive and programmatic lead to the decision on operators. I can’t tell you how many times and how many hours we spendt trying to find a way around this. Bruce Payette’s book PowerShell In Action goes into all the details. Anyway – the point is you are on solid ground here. That said, as much as I disllike those operators, I am actually extremely happy about how we balanced an interactive vs a programmatic shell. Of course if that is not the development model you use, then this brings you no benefit.
Many of the other things in this article I would put into the bucket of needing to better support a developer mindset (except for the required {}s for if statements which falls into the category of – we are just going to be buttheads on this because it is a bug farm and responsible for so many wasted man-centuries of grief). From the very beginning of PowerShell I was clear that we wanted a single tool to span the needs of both developers and operators (we were devops before devops was cool :-)). The reality is that we started out heavily skewed towards operators (e.g. the importance of the admind development model) and then release after release, we are expanding to better address developer sensibilities. This is one of the primary focuses of PowerShell V5 which is in preview and provides support for classes and a new developer-oriented language mode (must declare outputs, returns are the only way to emit objects, no dynamic scoping, etc. etc). I talked about the shift to focus on developers and devops scenarios at my recent talk at the PowerShell Summit in Amsterdam. Check out https://www.youtube.com/watch?v=j0EX5R2nnRI&index=1&list=PLfeA8kIs7Coehjg9cB6foPjBojLHYQGb_ around the 1:07 mark.
Many of those changes came because of other people that where kind enough to be honest and clear about what they hated about PowerShell so again – thank you for the gift on honesty and clarity. I really appreciate it and we do really take these messages to heart. It would be great if you could check out the new language mode in PS V5 preview (used when you code classes) and let us know what you think about it. I would hold off a couple of weeks and use the PS V5 Nov preview as the Sept preview classes had a number of issues.
Cheers!
Jeffrey Snover[MSFT]
Distinguished Engineer and Lead Architect for Windows Server and System Center.
So this thread essentially breaks down to:
Powershell uses poor design because it needs to support the poor design of it’s predecessors….
Seriously, it’s this mentality that makes me hate nearly all things MS….
Kevin, when you mentioned poor design… to which language do you compare it with?
honestly, powershell is by far the best language designed for its purpose…
I would like to say it “could” be the best language of it’s kind — but it is not. Here are a few “poor design” elements:
– Backward compatibility spotty at best. Grab a random old Powershell example from the Internet and try to run it…often it will not run without first being tweaked. (Compare to bash or dos, which will run just about any old script)
– Syntax structure is not consistent across modules, or sometimes even within modules. (compare to virtually any scripting or programming language, most of which have well defined syntax consistent across all commands)
– Rules around when parenthesis are required around a commend vs. when they are not is unclear
– Error messages are often of no help (compare to bash cli, which provides very helpful messages)
…etc, etc, etc.
Better examples — bash, dos, even vbscript, just about any unix shell (essentially bash). I know, at first you say “but that is not as powerful”. I agree — but the question here is one of design, not power. Build on a good design, and you get well designed power. But Powershell failed to build on a good design, so instead it is a powerful mess. Not the best of it’s kind, quite the opposite — the worst of it’s kind.
@cookieMonster – it looks like you must have read Bruce Payette’s PowerShell in Action because your analysis is spot-on!
I was particularly impressed by your insight into why functions have to be declared before they can be used – that is exactly correct – we wanted to ensure that you could take any script and paste it into the interactive shell and have it work.
Cheers!
Jeffrey Snover[MSFT]
Distinguished Engineer and Lead Architect for Windows Server and System Center.
Hi,
About the comparison operators. According to Bruce Payette– head developer of PowerShell– in his book PowerShell in Action, the reason they choose not to use equal-symbol symbols is that PowerShell is a shell. Pretty much every MS shell for 20 years used the symbols for output redirection, and there are all sorts of usages through cmd.exe and elsewhere that depend on redirecting output like this.
For instance, you currently redirect error level output using the following: Get-Process none, Powershell 2>&1
Anyway, I believe the logic was to base the decisions for PowerShell off of a similar Unix command, rather than contemporary scripting languages like Perl or Ruby.
Another reason that comparison operators are like they are is consistency. Even if msft had used >, < etc in the set of valid operators, there would always be operators that are not easily noted using simple keyboard symbols (without the hon-transparent approach used by APL, an earlier progamming language). The way that was adopted means ALL operators begin with a '-'; a bit of consistency that some find useful. It certainly aids discovery, IMHO.
Besides lacking the already mentioned one line IFs “if (condition) action” I would also love to have ternary operators support, it would really simplify and shorten the condition notation.
And here is the thing I hate most and can’t understand what was the reason for this:
“In Windows PowerShell, the results of each statement are returned as output, even without a statement that contains the Return keyword. Languages like C or C# return only the value or values that are specified by the Return keyword.”
^ from http://technet.microsoft.com/en-us/library/hh847760.aspx
To give you an example:
function test($a)
{
write “Text in function”
return ($a * 2)
}
$result = test 5
write (“Result in main: ” + $result)
OUTPUT:
Result in main: Text in function 10
but reasonable output for developers would be this:
Result in main: Text 10
I can’t understand the logic behind this. We must design functions in our scripts to be very quiet or use other channels like verbose or debug. Hopefully Jeffrey Snover can explain the reason why this decision was taken :)
@Martin
That is one of the things we address with the new language mode found in classes. There you have to declare your return type, use a return statement and write-output goes nowhere.
The historical reason for this is PowerShell’s footing as an interactive shell. Ignore the “return” statement and that is exactly the semantics of interactive shells. We added the return statement to make it more friendly to developers but this one of those situations where when you add something, you make it dramatically weaker. Like:
I’m loyal to my spouse.
is made weaker when you add:
…on Tuesdays.
Having made the mistake of adding it, removing it (or ignoring any write-output if a return statement is used) would be a breaking change. That is why we waited until we had a new language mode to address it.
Jeffrey Snover[MSFT]
Distinguished Engineer and Lead Architect for Windows Server and System Center.
It does amaze me how developers expect things to be like they are in a compiled programming language
PowerShell functions are just a kind of command like ping. ping() makes no sense. But when you have a Method of an object it’s arguments are bracketed…
Operators: yes of course it should be ping > file.txt and it and get-date > $mybirthday good luck sorting those out.
{} round script blocks, seriously ? Yes C style lets you out of including them sometimes, although it can create so brilliant bugs …
But PS gives you the same syntax for
begin, process & end block in loops, where conditions [if script block returns true, pass object along the pipe line], do/while bodies, function bodies, even in parameters consider this:
dir | ren -newname {$_.name -replace “foo”,”bar”}
So the syntax of if () round the expression to be evaluated {} round the code to run isn’t that hard. And how can someone complain that variables don’t have to be declared but the ends of an IF block don’t have to be ?
Not using \ for the escape character … so you have a path in a string, and you’re on windows “C:\really\simple\problem” if you have \ as the escape character : whatever you use instead is going to feel wrong.
Mandatory variables declarations make ZERO sense in a typeless language
If I have to declare VAR: $foo
but I can the write $foo = ping (foo holds an array of strings) or $foo = get-date (foo holds a dateTime object) declaring the variable didn’t enforce anything except extra work
Naming variables before you use them isn’t declaring : declaring is saying I have a variable of this type and it has this name.
So when I was working on exchange earlier today and I did $u = get-umserver , you have me devote time to finding out what type of object get-umserver returns and then declare U as that type first ?
You want to declare variables before you use them, but not functions ? Why ? It’s a scripting language it’s interpreted . if it were compiled it might make sense to parse the whole thing to find named script blocks (functions) and save them but it’s not. Yes I grind my teeth when I alter a bit of code and introduce a syntax error which only comes to light when a lot of script has run. But that’s what the ISE is for.
I disagree that PS should be treated only as a glue. It is certainly more than that and is more than a scripting gateway to .NET. Why would PS need modules, invocations, functions, objects etc if it were only a glue? Command prompt did not need them. Even bash leaves most of this to be implemented elsewhere. PS has definitely aimed at the big league. Not quite there yet, is it?
@James,
Variable declaration is a welcome feature. No need to specify type. Take javascript as an example.
For PS it is double important because of dynamic scoping. Frankly, I am struggling to understand why they introduced that thing. To save on look-ups?
Anyway, dynamic scoping is quite a bug breeder. At present, the only safe practice is to explicitly initialize all local variables before any use. You’d say, this is a good practice anyway. Well, the thing is, in some situations it comes at the cost of code clarity (e.g. recursion). For some reason they introduced default values in PS… Alternatively you may use explicit scope prefix for every instance of the local variable. That would be a little bit more expensive than just initialization :)
Whether to put function definitions on top or not, it is a preference. The problem is PS is throwing a run time error when the function is not defined; the error can be silenced. So if code calls ahead and fails first time, the missing function maybe added after recovery from the rte. I guess on next run the behavior might be a bit different. Good luck catching this!
I pretty much have a similar background, and the article is spot-on!
There are a lot more annoyances, mostly minor ones. But you forgot one important one (at least for me ;-) ). Inconsistency, this one really bugs me. Let me give an example:
why does the given example:
dir | ren -newname {$_.name -replace “foo”,”bar”}
work, but:
dir | echo $_.name
doesn’t work, it’s an issue I see a lot and when using the the pipe. I know that the second command needs a foreach to work: dir | % { echo $_.name} does work. And I get why, but I have a programming background, but for people with no programming knowledge, it’s a deal breaker.
The second inconsistency example is in variables, the idea was that powershell could decide what kind of variable/object type a variable should be, this is good for admins who try scripting. I’ve encountered several cases in which regular cmdlets sometimes pass the object as an array when actually, it’s only a single object. This obviously results in an error when trying to use the result in another function. The annoying part, it doesn’t do it every time. And when it happens, it’s really time consuming. Defining [string]$variable helps in this case.
I think it would have been better for powershell to be good at 1 thing, instead trying to be good at scripting and trying to be shell-like. In the current form, it doesn’t really excel in either.
Eric,
dir | ren -newname {$_.name -replace “foo”,”bar”}
This is an example of what’s generally referred to as a “ScriptBlock Parameter”. The reason it doesn’t work with Write-Output (or echo, which is an alias), is that Write-Output’s parameters don’t accept pipeline input.
When a parameter does accept pipeline input, you can assign a ScriptBlock to that parameter instead, and PowerShell will evaluate the script block for each input object in the pipeline (setting the $_ variable to that input object). You can see this in action with Trace-Command:
trace-command -Expression { dir | ren -newname {$_.name -replace ?foo?,?bar?} -WhatIf } -PSHost -Name ParameterBinding
… snip
DEBUG: ParameterBinding Information: 0 : BIND PIPELINE object to parameters: [Rename-Item]
DEBUG: ParameterBinding Information: 0 : Invoking delay-bind ScriptBlock
dir | ren -newname {$_.name -replace “foo”,”bar”}
Works because the FileInfo or DirectoryInfo objects passed into Rename-Item (aliased to ren) get bound to the LiteralPath parameter and you are specifying $_.Name for the -NewName parameter.
dir | echo $_.name
Those same objects, when piped to Write-Object (aliased to echo), are bound to the InputObject parameter. No other parameters on Write-Object are “positional” i.e. you have to specify the parameter name. But given your example it is clear that you wanted $_.Name as the argument to the -InputObject parameter. In this case, what you want to use the Foreach-Object command (aliased to foreach) which allows you to execute arbitrary script on any object passed to it e.g.
dir | foreach {$_.Name}
In PowerShell v3 this has been further simplified for scenarios when you just want to access a property to:
dir | Foreach Name
And if you really want to keep the typing short (only recommended for interactive/command line usage due to readability) you can use another Foreach alias – %:
dir | % Name
>> I think it would have been better for powershell to be good at 1 thing, instead trying to be good at
>> scripting and trying to be shell-like. In the current form, it doesn’t really excel in either.
Hmm, never used Korn shell or Bash eh? :-) Unfortunately this is a problem of Microsoft’s own making by waiting so late to provide a decent shell on Windows. Windows users just aren’t used to what a powerful shell can do in conjunction with a powerful scripting language. That said, Windows has the batch language but not many folks use it. If you think PowerShell syntax is funky, trying iterating through files in a for loop in a .BAT file.
I think folks need to be a bit careful comparing PowerShell to scripting languages like Python and Ruby. PowerShell is a “shell” scripting languages and that has specific semantics like not having to quote every argument and being able to execute exes directly. For example typing:
import os
dirlist = os.listdir(“c:\\temp\\foo”)
from pprint import pprint
pprint(dirlist)
at the prompt would kind of suck compared to:
dir c:\temp\foo
>Script syntax check
Your example script is valid syntax; “aslkfjlsjdf” might be you running “c:\windows\system32\aslkfjlsjdf.exe”, or it might be a CommandLet alias defined by something else.
My background is FORTH and LISP. When the “C’s” became the standard I hated the ‘black-box’ compiling and especially the strict type casting.
The language I learned first was FORTH and FORTH’s best features were:
— it became the operating system
— it could be compiled
— it could be interpreted
— it could interpret while compiling
— parentheses ARE the comment character (just as regular English)
Windows PowerShell is a scripting language and as such is, of course only interpreted. While it is not the operating system, it is a shell and command language, like BASH and others. Windows PowerShell, however, returns everything in object form automatically — putting it head and shoulders above the others.
Windows PowerShell is verbose, verbose, and sometimes is strange when trying to mesh with ‘pure’ .NET operations; but overall, PowerShell rocks.
PowerShell is just beautiful! It`s not a programming language it`s a task automation and configuration management framework built on top of .NET. It contains a scripting language and interactive shell. If you want to build applications and services use C#, if you want to automate your infrastructure, OS and applications use PowerShell, why compare powershell to compiled programming languages?
You just read my mind!
It’s very ugly and hard to understand/troubleshoot language (I have ~20 years of developer experience, so I can compare things). Microsoft, as always, tried to re-invent a wheel. Why not make something similar to C# or javascript? Especially if Powershell use .NET. Or at least no need for these ‘very special syntax’ described in you post.Suspect it will be replaced in very near future by more friendly scripting language (even by Node.js, why not?)
Interesting read. I do share some of these sentiments, however, I still no less think that PS is by in large a huge leap forward for DevOps, Devs, SysAdmins that used to rely on the kluge of VBScripts, BAT files, and god help you a set of JScripts. From the time you wrote this, I wonder now if you still share the same notion especially since you now have Bash on Windows and PowerShell on Linux. Bash also would seem to follow several of these complaints as well as Python. This begs the question: What do you feel would be a more authoritative scripting language?
Here’s some REAL reasons why powershell is crap:
1) Powershell-ISE, the intellisense doesn’t work inside functions, only when you are running things from global scopes. If that’s not broken enough, you need to run things first in order to “see” variables in com objects. Unfortunately with Com you need intellisense.
2) DLL contents appear and disappear randomly. Yes that’s right sometimes a script works sometimes it does not, depends on whether powershell can see the things you need inside the DLLs. if you can’t then you’re screwed.
3) Autoloading of modules. Autoloading of anything whatsoever in any language is a terrible idea, but dozens of people have complained about powershell sometimes loading modules and sometimes not.
I find that the module and manifest creation can be quite powerful and easy to produce once you learn to use it. (Granted this learning curve took awhile to overcome) However, I now find it quite easy to create large robust structured modules that I can import to my various programs. For instance I have made several powershell wrappers around various API from all over the place and I can now create insane GUI based applications just by importing the right set of modules. This makes powershell 100% worth it.
Pretty much everything in powershell follows this pattern: Supper clunky and hard to use – 2 months of struggling – how did I live without this?
Brilliant blog – with a vibrant and impressive collection of feedback comments! I am a developer, and I too feel your pain. I would have to agree with most of your PowerShell complaints. I was highly entertained by the Microsoft MVPs that hopped on-board to defend their product. I would just like to log my opinion. Being a C++, C#, Ada software developer, we often need to do administrative things. For example, with chocolatey there is often a need to write installation/uninstall scripts. So we are forced to follow the industry standard, which clearly seems to be leaning towards PowerShell. It IS a powerful, elegant, and cleverly designed scripting language. But it does indeed have its shortcomings, most of which you have already mentioned. It is just unfortunate that Microsoft failed to adopt many of the things that Perl got right. Like logical operators, pattern-matching, and function calls. For my scripting needs, I have been a fan of Perl for many years. It even had CPAN modules, which tried to accomplish what the new Cmdlets do. But Perl was difficult to tame. Scripts could easily get massively complicated and difficult to maintain, almost to the point of becoming cryptic.
PowerShell has the programmability of a developer’s language, but the feel of an admin’s scripting tool. The Object-oriented nature of its functions and Cmdlets greatly contributes to its upward scalability. Now that the wheel has been re-invented, and it is now backed by the awesome power of .NET, let’s just keep moving forward. I will swallow the PowerShell pill, but not without a pinch of salt.
A lot of good discussion here, and a lot of points of view. So, I’ll add my own. Over the years I’ve programmed in many languages on Mainframes, Minis and PCs. High level and machine code and everything in between. It’s just syntax/grammar. Just like spoken languages, just syntax and grammar. You get get to know it as you use it. Some are similar, some are wildly different. Java, Pascal, C, Python, Basic, Forth, APL, Lisp… you get the idea. PowerShell is VERY powerful. It took me three separate attempts before I felt comfortable enough to forge ahead. I now quite happily use it daily.
My only real complaint with PowerShell is that it’s slow. If speed is not an issue for the completion of a task PowerShell is my friend. If speed IS an issue and I don’t “need” PowerShell, I use VBScript. Lightning fast but more verbose to write.
Please Microsoft, speed up PowerShell. It’s a slug. A very strong, versatile, slick slug, but a slug none the less.
I’m a quasi-noob learning C# and PowerShell simultaneously. I may be wrong, but one sniggly hangup I’ve run into with PowerShell is that if I code an app in PowerShell/XAML, wrap it in an .exe and distribute it to users… it may or may NOT run on the user’s system if user’s workstation is missing some PowerShell cmdlet. But if I code my app in C# it will run on every workstation, every time. When we are talking about 5,000 workstations, even a 3%-5% failure rate is too much.
Powershell was never meant to be used as a base for Applications on client computers for exact the reasons you’re addressing. Use C# or any other suitable programming language instead
Interesting comments from several people. Here is my take. PowerShell is great for me, never used perl,bash,awk etc ., I am not a developer either cannot write in C# or VB can write in VBScript. Powershell is great for me to administer 10,000 windows servers across serveral domains
Can get lots of inofrmation form the OS from the command line. I can write a PowerShell module and give it to my team mates to run.
Its only been going since 2006 it will improve for the developer types but for us Windows administrators its great
Hi Gents,
a colleague and myself – we do honestly know so much about powershell – had to investigate a performance problem. our (64 core monster) servers, both in a cluster were running at 100% cpu for periods > 1min, were unresponsive to remote desktop due to powershell instances, up to a few hundred at a time which do essentially Invoke-Command (executing an exe on a remote server in the same domain, same datacenter. we noticed that cpu usage for simple commands was enormous (20 to 50 seconds of pure kernel cpu for a simple command). so we looked with sysinternal tools to find out more and started to googling for performance aspects with the following results:
– I was a bit shocked about the low knowledge level of the main google hits – it appeared that no one with deeper knowledge about non functional aspects uses ps or posts insides about it
– commands, syntax and other aspects I personally consider in most cases weird – I wonder, as an example how the creator of measure-command came out with what the command gives out (several lines for the same, single value in various units. on linux it would be a matter of a formatting step…this is weird and > 50% of what I see I’m concerned
– the options given to the commands we try require to be specified in a certain order!
– no insights could be found explaining what happens in the background, which properties could be tuned to make run it better.
so we started poking around and were lucky already on the first day. We noticed that on a 2008R2 machine it performed better than on the new ones 2012R2, so we forced -Version 2.0 (at the right position in the command line of course) and that fixed the problem for us. CPU went down dramatically when using v2 instead of the default v5 on this box. that was pure luck.
PS seems to be a typical MS tool, which is OK for occasional usage if you can bear the weirdness coming with it (i.e. differing from traded standards in many aspects, just like internet explorer did), but I regret the day back when we decided we don’t want to bother install SSH daemons on the servers. “time to market” was shorter but we have paid this initial gain back and more than that since as every now and then we have to find a solution (most of the time it is functional where things sporadically do not behave as their are described/specified, often without finding a good reason).
The episode yesterday was just take somehundredsomthing in the tale of “this platform sucks” (while windows has its good sides – a few at least). MS is good – it keeps us busy and so pays our rent :)
because of using communication offered by MS we’re forced to run on windows. the part not needing this we offloaded to linux (same HW) some months ago and there it performs about ~5 times better – well very rough observation since we just looked how long it takes after an instance started before it is fully ready (sometimes 1000 threads and more are to be spawned).
Also the syntax changes based on command, for instance, you want to get a group from a specific domain, you’d user get-adgroup -identity “group@domain” -server “domain”, likewyse for distribution groups you’d use get-distributiongroup -identity “group@domain” -DOMAINCONTROLLER “domain”
everyday i find these inconsistencies, it really sucks at being uniform
You know how I know you’ve never done any Unix shell programming? Powershell was deliberately designed to have a Unix-like look and feel. It’s syntax and operators are very similar to the BASH shell. It’s just more klugey. Just be happy that the fine folks at Redmond finally listened and provided a scripting language for systems maintenance at all.
Got to disagree, Will. Azure CLI is designed to be more Unix/bash like. PowerShell is just it’s own messed up world that borrowed a few things from Unix. “Borrowing” concepts is quite a bit different than being based on solid footing.
Most of these seem pretty superficial tbh. The only real gripe I’ve had so far is scoping, and while it hurts to understand it does technically provide more flexibility if you can keep track of it. Also the functions not using parameters but object methods using parameters was momentarily confusing…
Some people here seem to think PowerShell is great just for not being as bad as what existed before it. If PowerShell is as good as it gets then that’s a really sad state of the industry.
But wait, Poweshell 7 is here! I mean – new, improved, better, great, rah, rah, rah! But for some reason there seems to be a huge need for running Poweshell 7 “side-by-side” with older versions? Installing PS7 leaves original Windows right-click menu pointing to 5.1? PS7 has bugs that are noticeable right away, and this is somehow better?
Can’t help but wonder when Microsoft will get a clue, retire Powershell, and put their effort into a solid base language. Kind of like they did for Windows Server when they FINALLY moved away from old NT Domains to LDAP (oops, I mean AD). Back then everyone told them the ill-conceived NT Domain model would not scale and would not work well, but Microsoft plunged ahead anyway. I feel like Powershell (for all reasons mentioned) is in the same boat. Time to cut bait and invest in a better underlying platform.
LOL — I a strange and timely turn of events…I’m doing some work with Service Principals, and read this great article by Net on the subject. (https://nedinthecloud.com/2019/07/16/demystifying-azure-ad-service-principals/). Scan to the part where he explains how to perform this task using Powershell! A perfect real-world example of why we hate PowerShell!
Compare to the simplicity of performing the same task in Azure CLI!
Yup, PowerShell really stinks!
So, this article is from 2014… The majority of comments ‘hating’ PowerShell (especially its syntax) keep it alive and well till today (2021-04-06)… I would say there’s a pattern there.
Me? I’m a DBA. I ADORE T-SQL. Recently I delved into PowerShell because there’s the project at my institution to change the interface we currently have between SQL Server and Active Directory from using FIM to PowerShell…
Boy….
The more I string::#${[()]} learn about PowerShell the more I hate it. (Especially the L-A-C-K of syntax standards).
Be well everyone!
Raphael
Its 2021, the syntax is still wanky and inconsistent.
Glad i’m not the only one who does not like powershell for more profound reasons.
function somefunction { param($number) return $number + 1 }
somefunction 123
somefunction(123)
somefunction -number 123
Why do we need 3 different syntaxes packed into 1 scripting language?
It feels like they put more and more crap into powershell and MS is already overwhelmed by the complexity.
Your example for function declaration does not make sense to me, it is like this in C, C++, php and posix shell (javascript overcomes this because of hoisting)
I disagree with operators -gt -lt beeing bad, thats how posix shell did it in the first place.
I like how they made the shell object oriented and the pipeline makes sense and is an enormous performance gain when comparing to the string parsing in unix-like environments.
* Unless you work with huge arrays of objects e.g. excel data, adding/removing elements results in creating a new copy of the entire array and makes you cry. (TIP: use hashmaps with integers as index if you ever hit this issue)
While jumping between unix and windows i was actually missing “| %{…}” on unix. (You can use “| xargs -L1 …” as a replacement)
However – it was a good read including the comments – thanks!
Every time I work with powershell I end up amazingly annoyed, it’s utterly horrible and inconsistant. I see people in here saying it’s great or elegant and wonder if they had ever seen another language, I’ve honestly never seen worse from a language not deliberately designed to be bad INCLUDING fortran, VB and possibly APL (At least it had consistency!).
The most crazy thing I’ve seen in powershell hasn’t even been mentioned here (that I’ve seen), it’s the way adding a line in the middle of a function can change the return type to an array. That shut me down for a DAY trying to figure out what the hell was going on. If I had realized the depths of depravity the developers had gone to I could have possibly figured it out, but NOBODY woudl expect anything that insane (evil? ignorant?), right?
VB, by the way, isn’t great, but OPTION EXPLICIT fixes one of the very worst things, without that I’d call it more of a joke than a language–I was interviewed by a company and asked what the first line of a VB file is, if you didn’t answer OPTION EXPLICIT, they ended the interview right there, you obviously weren’t a programmer, With powershell creating variables on the fly isn’t even close to the worst thing wrong with the language, but it’s still one of the worst things I’ve seen in any other languge!
I think you hit on something — have they ever SEEN a real scripting / programming language? Maybe the people who rave about PowerShell do so because they have never experienced anything better than Windows (aka DOS) script.
“Oh it’s so powerful”, “Oh look, I can iterate over objects”, “I can have conditional elements in my script”, etc., etc. Yea, so what? Isn’t that kind of like raving over a car because it has 4 tires?
Yet another thing to add to the list. They change stuff for no apparent reason, and seem not to even attempt maintaining backward compatibility.
I was just fighting with getting something working. Turns out I was referencing some older PowerShell that used backslash as the escape character. Suddenly it hit me that PowerShell now uses the grave quote as escape…and that’s why the old code was tossing errors!
Microsoft designers lost it with PowerShell, it is a total disaster.
I equally feel same sentiments with Klein Helge and many other developers here and around the world.
I can’t believe they let Python take over scripting language space while C# had the greatest opportunity to be on top. C# had 6 million developer followers that could have been on top of it but instead, they went and created a brand new language called PowerShell scripting language (for whom did they make that language for, why so different and confusing yet siutting on top of .Net Framework.)
PowerShell scripting language is a mess, not adoptable, very confusing to use and unnecessary learning curves.
All they needed was an executable that will run a csharp.cs file from command prompt, end of story.
This would be very easy for anyone who wants to use C# for system admin work or developer work alike.
There are 6 million developers out there available to help and teach C# script to anyone, System Admins will be able to easily learn it quicker than PowerShell and they will have support all over the place both locally and remotely.
The code/script will be usable anywhere needed.
You can create your csharp.cs script file from Visual Studio, Visual Studio code or any editor of choice and it will make no difference.
It will be very easy to teach in the schools hence the continuity of C#.
And whatever you learnt from school will be a direct transfer to real-life, one-to-one.
Due to lack of above mentioned points, Python capitalized on them and in very short time took over C#
and leading the way with over 11 million active developers.
I have no idea what came-of Microsoft designers but they lost it completely and missed the opportunity to be relevant on today’s data science, machine learning, data management and analytics activities.
Nonetheless, it is not entirely too late as they can reverse course and bring C# file execution to command prompt just like python and it will instantly begin to compete with python again.
But rightnow, its python all the way with no competition and if they manage to get python to a similar IDE like SSIS environment then C# will be completely dead and will be buried.
Example, on my present environment, the senior management doesn’t care very much about C# or SSIS, all they say is use python to do it, python should be the standard environment.
Chris Agwu
24 years in Application Development
Data Services Manager/Architect
New York City
The Connect link doesn’t work.
This just seems silly. Maybe it’s because I’m one of thos admins for whom PowerShell really was my introduction to scripting. A lot of the complaints you have are really just preference. Having come from PS, I struggled learning node.js because I thought ITS logical operators were silly. I liked the backticks in PowerShell for indicating new lines, as I found them cleaner than a backslash…
But now I know node.js and some python… I’m still more fluent in PowerShell, and I like node.js and python, but I have no beef with PowerShell.
In fact, one thing PowerShell has that I wish more languages had is the get-help cmdlet. Can’t remember a cmdlet or looking for an cmdlet relating to AzureAD? Just type “get-help *AzureAD* ” and you will get any and all cmdlets involving AzureAD, as well as documentation.
Boy I wish Node had that.
I could not agree more. PowerShell is complete garbage.
My background: full time full stack Web developer for 15 years. ASP and ASP.NET. And a hobby programmer just learning and playing with software development.
And I spent most of my 20’s using GNU+Linux personally and enjoying the paradise that a functioning operating system is like.
I’m well versed in C, C++, C#, JavaScript, Perl, and SQL (maybe not exhaustive). I’ve also dabbled with Lisps and Haskell, but not enough to pick them up.
I prefer command terminals to interact with the computer for non-audio/visual tasks.
I have extensively written and maintained Bash scripts running in Linux, as well as Windows’ Batch/Command scripts for work tasks because I can rely on that being there (and not much else). And I’ve tried, really hard, to learn PowerShell. To learn to like PowerShell. I cannot.
PowerShell is just a bad product. It is meant to be a powerful shell, I would assume, from the name. But what does a powerful shell do? Honestly, the best way to answer that is simply to point you to a shell that is much better: something like Bash. It isn’t perfect. It has its wrinkles. But it has also proven itself to be very powerful.
When a Bash programmer sits down with PowerShell and tries to learn to do things they can normally do they will find that they cannot do most things. Or if they can do them, they might not be able to find good documentation to learn how to. For something backed by a megacorp and with such a name, it’s really sad what the end result has been.
When I first read about a shell that transferred objects between programs I thought this could be really powerful. I was envisioning something that had first class support for all existing features from Unix-like shells, but with the capability to transfer data between programs with runtime types. Instead of just a stream of data, it could be an object that you could interact with, inspect or modify attributes, or call methods. This could have been powerful. BUT: you have to solve for how to be compatible with non-PowerShell programs. There needs to be a sensible way to convert the objects into a stream of data that could be utilized by a non-PowerShell program. And back again.
At this point, I don’t think it’s worth trying to salvage the project. I say kill it with fire. If such a thing is even needed (an object-aware shell), the open source world (so some lone individual initially until they can bootstrap something useful) is going to have to do the work. And people that actually do extensive, complicated shell scripting and know what features will be expected.
I think what we really need is a way for the computer to abstract all of the different ways that code can be run – everything from native compiled code to bytecode runtimes and interpreted text (executables in the file system), arbitrary functions/methods in library files, and Web or Internet services. And the user gets to easily wire any of these together into a pipeline.
Though perhaps at this stage it’ll instead come down to using LLMs to talk to the computer instead and have the computer learn how to do things from online sources and wire everything together itself..
Powershell’s default-immutable parameter-passing seem like C#’s ‘in’ and ‘ref readonly’ modifiers.
You may use the . (period+space operator) instead of & to mutate parent-variables within a called-function instead of override them; For more information, please see https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes?view=powershell-7.4#using-dot-source-notation-with-scope
My code is flagged as spam, so see https://stackoverflow.com/a/72998143 for a useful function to see a variable’s scope relative to the current function (that is, where scope-level=1).
Another fascinating quirk is this under-the-hood secret conversion, where an array is silently (or treacherously?) converted into another completely different type:
function ReturnArray_One_Element {
$array= @(‘Element 1’)
return $array # Note, an array is returned
}
function ReturnArray_Two_Elements {
$array= @(‘Element 1’, ‘Element 2’)
return $array
}
# NOTE: Both previous functions return an array.
# Let’s call them:
$array = ReturnArray_One_Element
Write-Host $array.GetType() # Prints… string (wtf?)
$array = ReturnArray_Two_Elements
Write-Host $array.GetType() # Prints… array
From time to time some wheel is reinvented, and surprisingly it turns to be an elliptical (or even squared) wheel, throwing away previous experience of languages that learned through years from there own mistakes, evolving and getting better (well.. not all, true).
And behind this new wheel, a troop of lovers march happily defending it, loving the funny quirks and bounces of the new wheel, even protesting against the boring and silent motion of the old wheels. And even more, they hate comparisons like the ones on this article.
Your article makes me think: Human kind drags an old and dangerous gene, the source of many conflicts… the tribal gene.
Once we get into a tribe (it may be your music style, your dressing style, your land of birth, your programming language…) something in your mind clicks, and you are likely to turn into a warrior to blindly defend it, accepting its defects as “not defects”, but on the contrary, defending them as a proudly part of your tribal identity.
If someone criticizes what they call “defects”, they are criticizing your own history, your past, your community… your tribe. Prepare for war, as sensed in some of the previous comments.
I add myself to the list of people awed by the curious shape of this powershell wheel, that keeps bouncing… when there was no need to.
Another funny quirk:
Try to run this:
Get-Location
It works fine, returning info of the current folder.
Now, run this:
$folder = Get-Location
It also runs fine. Now, run this:
$folder.ToString()
Also fine. Where is the problem, you may ask? Here you are, try this:
Get-Location.ToString()
It should work, as “Get-Location” is the same as “$folder”, you did the assignment right before.
The symbol “=” means that both terms are the same. However, error is returned!!! (sorry, Spanish version):
En línea: 1 Carácter: 23
+ Get-Location.ToString()
+ ~
Se esperaba una expresión después de ‘(‘.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedExpression
Have you ever known of a programming language that, after assigning one object to another, by creating a copy or a reference, they behave different?
A hooligan (there are always!) can argue that there is a subtle process behind the assignment that only chosen people is able to understand.
But the question remains: Have you ever known of a programming language that needed to alter the concept of assignment to that extent? Don’t you perceive it as a design flaw?
I’ve been coding software for years, and I have many small pieces of software in various programming languages. Powershell is the worst thing I have ever seen, either something is wrong with the people who love Powershell or with me. HUH