Isilon-POSH icon indicating copy to clipboard operation
Isilon-POSH copied to clipboard

Using `-WhatIf` or omitting `-Confirm:$false`/`-Force` fails on functions

Open kbakk opened this issue 8 years ago • 1 comments

I noticied this when running the commands Set-isiClusterOwner -location "Bergen"

Expected: The command should prompt if I want to continue, stating the cluster I'm performing the action on.

Actual:

Set-isiClusterOwner : The variable '$parameter1' cannot be retrieved because it has not been set.
At line:1 char:1
+ Set-isiClusterOwner -location "Bergen"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (parameter1:String) [Set-isiClusterOwner], RuntimeException
    + FullyQualifiedErrorId : VariableIsUndefined,Set-isiClusterOwner

Going through IsilonPlatformSet.ps1 and IsilonPlatformRemove.ps1, I notice several cases where $parameter1 is not set.

This may be related to #12 .

kbakk avatar Aug 08 '17 08:08 kbakk

I tried to work around this by adding the line if (-not (Test-Path variable:parameter1) ){$parameter1 = "Inhereted from session"}.

This allows me to run with -WhatIf, but I then see a new error:

Set-isiClusterOwner : The variable '$ISIObject' cannot be retrieved because it has not been set.
At line:1 char:1
+ Set-isiClusterOwner -location "Bergen" -WhatIf
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (ISIObject:String) [Set-isiClusterOwner], RuntimeException
    + FullyQualifiedErrorId : VariableIsUndefined,Set-isiClusterOwner

This made me investigate this error (VariableIsUndefined), and I found that it's an error thrown when a variable is undefined and Set-StrictMode -Version Latest is set. This is the case here (it's set in IsilonPlatforSet.ps1).

kbakk avatar Aug 08 '17 08:08 kbakk