Windows PowerShell in Action

Category: Operating Systems
Author: Bruce Payette
4.0
All Stack Overflow 7

Comments

by David Mohundro   2017-08-20

It can be if you need it to be.

Like so:

[1] » [int]$x = 5
[2] » $x
5
[3] » $x = 'haha'
Cannot convert value "haha" to type "System.Int32". Error: "Input string was not in a correct format."
At line:1 char:3
+ $x  <<<< = 'haha'
[4] »

Use the [type] notation to indicate if you care about variables being strongly typed.

EDIT:

As edg pointed out, this doesn't prevent PowerShell from interpreting "5" as an integer, when executing (5 + "5"). I dug a little more, and according to Bruce Payette in Windows PowerShell in Action, PowerShell is actually a "type-promiscuous language." So, I guess, my answer is "sort of."

by anonymous   2017-08-20

I've been in the same situation. What I finally did was close my CMD window that was normally open all day and keep the PowerShell window and force myself to only use it.

I only resorted to CMD when something was urgent and I didn't feel I could take the time to figure it out in PS.

I'm still not quite as proficient in PS yet, but I'm getting better everyday.

Below are a couple good books and some links to some good resources.

I liked these two books a lot:

Also, check out these sites:

  • MS Script Center
  • Scripting with Windows PowerShell
  • The PowerShell blog
  • PowerGUI
by anonymous   2017-08-20

It's a reserved keyword (like return, filter, function, break).

Reference

Also, as per Section 7.6.4 of Bruce Payette's Powershell in Action:

But what happens when you want a script to exit from within a function defined in that script? ... To make this easier, Powershell has the exit keyword.

Of course, as other have pointed out, it's not hard to do what you want by wrapping exit in a function:

PS C:\> function ex{exit}
PS C:\> new-alias ^D ex