locked
Unable to find type [System.Windows.MessageBox] Runs in ISE but not from powershell RRS feed

  • 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.

    Result

    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

All replies