Converting VBScript's IsObject Function

Definition: Returns a Boolean value indicating whether an expression references a valid Automation object.


That’s a good question: how can you tell whether or not a variable is an object reference; that is, how can you tell whether a variable is a pointer to a COM object or a .NET object? Well, one way is to invoke the -is parameter and see if the variable really is an object. For example, in the following two commands we create an object reference named $a. We then check to see whether or not $a is an object reference, with the resulting value (True or False) stored in the variable $b:

$a = new-object -comobject scripting.filesystemobject
$b = $a -is [object]

When you run this command and then echo back the value of $b you should get the following:


As we intimated, .NET objects will also be identified as objects using this command.

Return to the VBScript to Windows PowerShell home page