PowerShell Quick Tips - What's in a Type
Troubleshooting scripts takes skill and you get better at it over time. One troubleshooting technique that I practice when I retrieve data from different sources, whether it be Active Directory, text files, CSV files, custom objects, etc., is to confirm that I am working with the correct data type. In other words, if I think I am working with an integer, but my variable is a string, I'm probably going to not get the expected output, if not an error. So, I make frequent use of the gettype() method. It is simple to use, just put a '.gettype()' on the end of your variable and it will display the data type that you are working with. See the following image for some examples.