Converting the Windows Script Host Exists Method
Definition: Indicates whether a specific key value exists in the WshNamed object.
In Windows Script Host the Exists method is used to see if a particular named argument was supplied when the script was started; for example, this line of code checks to see if an argument named ServerName was included when the script was launched:
Note. If you aren’t sure what a named argument is, it’s simply the name of a specific argument (e.g., ServerName) followed by the value of that argument (for example, the name of a server). In other words:
Named arguments aren’t an integral part of Windows PowerShell (although there are ways you can fake the process); therefore, PowerShell has nothing analogous to the Exists method. However, it’s easy enough to see if a specific value was included in the command-line arguments used when starting a script; all you have to do is use the –contains operator against the arguments collection ($args). This command returns True if atl-fs-001 was one of the arguments supplied to a script, and False if atl-fs-001 was not one of the arguments supplied to a script:
$args -contains "atl-fs-001"