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.
paddy75
Posts: 21 Joined: Fri Sep 04, 2020 7:59 am
Post
by paddy75 » Mon Sep 14, 2020 10:10 pm
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:
if ( -not ( Get-PSSnapin -Registered | Where-Object { $_ .Name -eq "Microsoft.Exchange.Management.PowerShell.SnapIn" } ) )
{
$buttonExchange .Visible = $false
}
else
{
$buttonExchange .Visible = $true
}
}
jvierra
Posts: 14676 Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:
Post
by jvierra » Mon Sep 14, 2020 10:35 pm
This is how to do this:
$buttonExchange.Visible = [bool](Get-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ea 0)
paddy75
Posts: 21 Joined: Fri Sep 04, 2020 7:59 am
Post
by paddy75 » Tue Sep 15, 2020 7:50 am
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:
$buttonExchange .Visible = [ bool ] ( Get-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn - ea 0 )
jvierra
Posts: 14676 Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:
Post
by jvierra » Tue Sep 15, 2020 1:28 pm
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: 21 Joined: Fri Sep 04, 2020 7:59 am
Post
by paddy75 » Wed Sep 16, 2020 4:05 am
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)