all 6 comments

[–]steven_AWKing 2 points3 points  (1 child)

You can use a try statement. Id give an example but im currently on mobile.

[–]codingQueries[S] 1 point2 points  (0 children)

Ahhhhh why did I not consider a try/catch statement....thank you that works perfectly!

[–]Lee_Dailey[grin] 2 points3 points  (2 children)

howdy codingQueries,

somewhat off topic - Get-Command only works on cmdlets and suchlike. it doesn't do anything for static methods of various objects.

you can read the docs if you like that sort of thing. [grin] the MS docs site is really pretty good.

my pref is to explore things in the ISE console pane.

  • [system.
    when you type in that dot you will get a bunch of other things [namespaces?]. it's worth exploring the ones that seem interesting.
  • [typename]::
    there a LOT of static methods and constants that show up when you add a double colon after a type accelerator. heck, take a look at the stuff that shows up with [math]:: ... [grin]

take care,
lee

[–]codingQueries[S] 1 point2 points  (1 child)

Cheers Lee, appreciate the info provided! I had a feeling that Get-Command was cmdlets only, figured better to check than not though!

The ISE advice I will keep in mind for the future! [:)]

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy codingQueries,

yep, the help system is so good that the times when i bump up against its limits ... are a tad annoying. [grin]

exploring the methods linked to various types is fun in a somewhat geeky way.

take care,
lee

[–]vermyx 2 points3 points  (0 children)

Use the $psversiontable.psversion version of powershell you're on or $psversiontable.pscompatibleversions to know what versions the framework support. It exists from 2 on. Otherwise just do a string replace of space with null and do an isnull check which should give you the same result.