check if pssnapin could be load

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Post Reply
paddy75
Posts: 3
Joined: Fri Sep 04, 2020 7:59 am

check if pssnapin could be load

Post by paddy75 »

Hello all,
I have a multi form project. The mainform has two buttons. In the formload i like to check when the exchange snapin is installed on the machine show the exchange button, when not hide it. I tried diffrent code, but all what i tried was not successfull. I tested it on the exchange server directly. Hope someone has an idea.
Here's the code I have at the moment:
  1.     if (-not (Get-PSSnapin -Registered | Where-Object{$_.Name -eq "Microsoft.Exchange.Management.PowerShell.SnapIn"}))
  2.  
  3.         {
  4.  
  5.         $buttonExchange.Visible = $false
  6.  
  7.         }
  8.  
  9.     else
  10.  
  11.         {
  12.  
  13.         $buttonExchange.Visible = $true
  14.  
  15.         }
  16.  
  17.     }

jvierra
Posts: 14544
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: check if pssnapin could be load

Post by jvierra »

This is how to do this:

$buttonExchange.Visible = [bool](Get-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ea 0)

paddy75
Posts: 3
Joined: Fri Sep 04, 2020 7:59 am

Re: check if pssnapin could be load

Post by paddy75 »

Thanks for your reply, but this is also not working. Button is not visible but snapin is installed.
We have Exchange 2013, so i replaced the name. I tried this now:
  1. $buttonExchange.Visible = [bool](Get-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn -ea 0)

jvierra
Posts: 14544
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: check if pssnapin could be load

Post by jvierra »

You have to use the exact name of the snapin.

At a prompt get the snapin and check the name. THe name you are using is not the3 name of the snapin.

paddy75
Posts: 3
Joined: Fri Sep 04, 2020 7:59 am

Re: check if pssnapin could be load

Post by paddy75 »

Name was correct. I found the mistake. the correct code is:

Code: Select all

 $buttonExchange.Visible = [bool](Get-PSSnapin -registered Microsoft.Exchange.Management.PowerShell.SnapIn -ea 0)

Post Reply