Answered by:
Unable to find type [System.Windows.MessageBox] Runs in ISE but not from powershell

Question
-
Add-Type -AssemblyName System.Windows.Forms [reflection.assembly]::loadwithpartialname("system.windows.forms")|Out-Null #Prompt the user if they are on VPN or not to pull the correct IP Address in results. $msgBoxInput = [System.Windows.MessageBox]::Show('Are you working on VPN?','IP Address and Host Name Information','YesNoCancel','Error') #Get the IP Addresses of all active network adapters and store in a txt file. Get-NetIPConfiguration | FT InterfaceAlias, IPv4Address -Autosize > C:\test\0000001.txt #Start the message box switch ($msgBoxInput){ 'Yes'{ ##Give IP Address of the VPN connection #Pull the local area connection line from Get-NetIPConfiguration results. $input_path = Select-String -path C:\test\0000001.txt -Pattern "Ethernet" > c:\test\0000002.txt #Select and format the IP Address $formatadr = ‘\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b’ #Set FinalLAN as a variable to store the formatted IP Address $FinalVPN = select-string -Path C:\test\0000002.txt -Pattern $formatadr -AllMatches | % { $_.Matches } | % { $_.Value } [System.Windows.MessageBox]::Show("IP Address: " + $FinalVPN) } 'No' { ##Give IP Address of the LAN connection #Pull the local area connection line from Get-NetIPConfiguration results. $input_path = Select-String -path C:\test\0000001.txt -Pattern "local area connection" > c:\test\0000002.txt #Select and format the IP Address $formatadr = ‘\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b’ #Set FinalLAN as a variable to store the formatted IP Address $FinalLAN = select-string -Path C:\test\0000002.txt -Pattern $formatadr -AllMatches | % { $_.Matches } | % { $_.Value } [System.Windows.MessageBox]::Show("IP Address: " + $FinalLAN) } 'Cancel' { ##End script and quit
I have been trying to get this code to run from a desktop shortcut. For some reason I continue to get the following error.
I was looking to implement this in our environment as an easier way to ask end users to provide network information based on LAN or VPN connection along with the users hostname. Right now we have to explain either cmd line to get info or direct them to an internal website. I want to add this to our gold image so it is available to new hires. Any help would be appreciated very much.
Jason Santoro A+ Network+
Tuesday, September 19, 2017 9:01 PM
Answers
-
To clarify, you have two ways to do this:
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.MessageBox]::Show('Hello')Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show('Hello')Somewhat helpful: System.Windows.MessageBox vs System.Windows.Forms.MessageBox
-Tony
- Marked as answer by Jason S_Mass Tuesday, September 26, 2017 7:04 PM
Tuesday, September 19, 2017 10:02 PM
All replies
-
Change all references for [Systems.Windows.MessageBox] to [Systems.Windows.Forms.MessageBox]
Also, I didn't need the first two lines (concerning the assembly) on my Windows 10 PC.
-Tony
Tuesday, September 19, 2017 9:13 PM -
MessageBox is in a different assembly.
Add-Type -AssemblyName PresentationFramework [system.windows.messagebox]::Show('hello')
To find these, do a web search for the Framework feature ("MessageBox Class") and note both the Namespace and the Assembly listed in the MSDN article.
https://msdn.microsoft.com/en-us/library/system.windows.messagebox(v=vs.110).aspx
Mike Smith TechTrainingNotes.blogspot.com
Books: SharePoint 2007 2010 Customization for the Site Owner, SharePoint 2010 Security for the Site Owner- Proposed as answer by Albert LingMicrosoft contingent staff Tuesday, September 26, 2017 2:44 PM
Tuesday, September 19, 2017 9:17 PM -
To clarify, you have two ways to do this:
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.MessageBox]::Show('Hello')Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show('Hello')Somewhat helpful: System.Windows.MessageBox vs System.Windows.Forms.MessageBox
-Tony
- Marked as answer by Jason S_Mass Tuesday, September 26, 2017 7:04 PM
Tuesday, September 19, 2017 10:02 PM -
Thank you. Changing it to Add-Type -AssemblyName PresentationFramework was what I was looking for.
Jason Santoro A+ Network+
Tuesday, September 26, 2017 7:05 PM