Forum Discussion
Error loading windows powershell PSSnapIn
Ok, I found the answer. I have been using the following lines of code that I have seen in many PS examples:
$checkSnapIn = Get-PSSnapIn iControlSnapIn -ErrorAction SilentlyContinue;
If ($checkSnapIn -notlike "iControlSnapIn) {Add-PSSnapIn iControlSnapIn};
What I found was the the if statement, the first time through failed to perform the Add-PSSSnapIn, even though the $Get-PSSnapIn command failed to populate the variable. It appears that the first time through, the $checkSnapIn variable is actually not defined, and when the Get-PSSnapIn command fails, the $checkSnapIn variable remains not defined.
To get around this (i believe new feature....) I changed the if statement as follows:
If ($checkSnapIn.length -eq 0) {Add-PSSnapIn iControlSnapIn};
So, when the Get-PSSnapIn fails, it will correctly evaluate the variable as having a "0" length.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com