When learning you will propably encounter a situation where you would want to know of which type your variable is… a string, array, integrr, boolean…?
At the time when you’re more advanced in PowerShell you will look at the code where you create the variable and know what type it is… but especially when you’re learning the basics this is not so easy.
So how do you know?
It’s actually pretty easy… all variables have the ‘GetType’ method attached to it which gives you the feedback what type the variable is 🙂
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
PS C:\Users\Jeff> $VarInteger = 123 PS C:\Users\Jeff> $varinteger.gettype() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Int32 System.ValueType PS C:\Users\Jeff> $VarArray = "1","2","3" PS C:\Users\Jeff> $VarArray.gettype() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Object[] System.Array PS C:\Users\Jeff> $VarString = "123" PS C:\Users\Jeff> $varString.gettype() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True String System.Object |
Here’s something that takes this and runs with it. http://jdhitsolutions.com/blog/2012/05/get-my-variable-revisited/
Hi Jeffery, Nice one!