Connect-MsolService in GUI pops up 3 message boxes, how can i supress these?

This topic contains 8 replies, has 2 voices, and was last updated by Profile photo of Dan Potter Dan Potter 8 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #34616

    I'm trying to migrate some stand-alone scripts into GUI form for ease of use, and i have moved onto our O365 scripts, so i need to connect-msolservice to enable the cloud cmdlets.

    while this works, unfortunately i'm getting some pop-ups for information that normally is displayed in the powershell window, 3 of them with "OK" buttons.

    Connection redirection, a waring about some imported commands including unapproved verbs, and newer version available.

    i've tried "Connect-MsolService -Credential $MSOnLineCred | out-null" to try and supress the messages but that doesn't work.

    any assistance would be appreciated

    #34635
    Profile photo of Dan Potter
    Dan Potter
    Participant

    I don't get any prompts at all after entering my credentials. Is this a first run thing?

    #34636

    well, i have the connect-msolservice in my $MainForm_Load section in the gui

    i do also have an import-pssession statement in there that i think is giving the initial connection redirection.

    basically what is showing in the pop-ups is the same informational messages that show in powershell when i connect

    #34639
    Profile photo of Dan Potter
    Dan Potter
    Participant

    try this, I don't get any prompts.

    function Call-testcred_psf {
    
    	#----------------------------------------------
    	#region Import the Assemblies
    	#----------------------------------------------
    	[void][reflection.assembly]::Load('mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    	[void][reflection.assembly]::Load('System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    	[void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    	[void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    	[void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
    	[void][reflection.assembly]::Load('System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    	[void][reflection.assembly]::Load('System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
    	[void][reflection.assembly]::Load('System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    	[void][reflection.assembly]::Load('System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
    	#endregion Import Assemblies
    
    	#----------------------------------------------
    	#region Generated Form Objects
    	#----------------------------------------------
    	[System.Windows.Forms.Application]::EnableVisualStyles()
    	$form1 = New-Object 'System.Windows.Forms.Form'
    	$textbox3 = New-Object 'System.Windows.Forms.TextBox'
    	$textbox2 = New-Object 'System.Windows.Forms.TextBox'
    	$textbox1 = New-Object 'System.Windows.Forms.TextBox'
    	$buttonConnectMSOL = New-Object 'System.Windows.Forms.Button'
    	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
    	#endregion Generated Form Objects
    
    	#----------------------------------------------
    	# User Generated Script
    	#----------------------------------------------
    	
    	$form1_Load={
    		
    	}
    	
    	$buttonConnectMSOL_Click = {
    		
    		$dnuser = $textbox1.text.split()
    		$sspw = convertto-securestring $textbox2.Text -asplaintext -force
    		$credential = New-Object System.Management.Automation.PSCredential $dnuser, $sspw
    		
    		
    		Connect-MsolService -Credential $credential
    		
    		
    		$textbox3.Text = (Get-MsolCompanyInformation).displayname
    		
    	}
    	
    	# --End User Generated Script--
    	#----------------------------------------------
    	#region Generated Events
    	#----------------------------------------------
    	
    	$Form_StateCorrection_Load=
    	{
    		#Correct the initial state of the form to prevent the .Net maximized form issue
    		$form1.WindowState = $InitialFormWindowState
    	}
    	
    	$Form_Cleanup_FormClosed=
    	{
    		#Remove all event handlers from the controls
    		try
    		{
    			$buttonConnectMSOL.remove_Click($buttonConnectMSOL_Click)
    			$form1.remove_Load($form1_Load)
    			$form1.remove_Load($Form_StateCorrection_Load)
    			$form1.remove_FormClosed($Form_Cleanup_FormClosed)
    		}
    		catch [Exception]
    		{ }
    	}
    	#endregion Generated Events
    
    	#----------------------------------------------
    	#region Generated Form Code
    	#----------------------------------------------
    	$form1.SuspendLayout()
    	#
    	# form1
    	#
    	$form1.Controls.Add($textbox3)
    	$form1.Controls.Add($textbox2)
    	$form1.Controls.Add($textbox1)
    	$form1.Controls.Add($buttonConnectMSOL)
    	$form1.ClientSize = '211, 241'
    	$form1.Name = 'form1'
    	$form1.Text = 'Form'
    	$form1.add_Load($form1_Load)
    	#
    	# textbox3
    	#
    	$textbox3.Location = '13, 182'
    	$textbox3.Name = 'textbox3'
    	$textbox3.Size = '168, 20'
    	$textbox3.TabIndex = 3
    	#
    	# textbox2
    	#
    	$textbox2.Location = '12, 70'
    	$textbox2.Name = 'textbox2'
    	$textbox2.Size = '184, 20'
    	$textbox2.TabIndex = 2
    	$textbox2.Text = 'password'
    	#
    	# textbox1
    	#
    	$textbox1.Location = '12, 27'
    	$textbox1.Name = 'textbox1'
    	$textbox1.Size = '184, 20'
    	$textbox1.TabIndex = 1
    	$textbox1.Text = 'Username'
    	#
    	# buttonConnectMSOL
    	#
    	$buttonConnectMSOL.Location = '12, 123'
    	$buttonConnectMSOL.Name = 'buttonConnectMSOL'
    	$buttonConnectMSOL.Size = '169, 23'
    	$buttonConnectMSOL.TabIndex = 0
    	$buttonConnectMSOL.Text = 'ConnectMSOL'
    	$buttonConnectMSOL.UseVisualStyleBackColor = $True
    	$buttonConnectMSOL.add_Click($buttonConnectMSOL_Click)
    	$form1.ResumeLayout()
    	#endregion Generated Form Code
    
    	#----------------------------------------------
    
    	#Save the initial state of the form
    	$InitialFormWindowState = $form1.WindowState
    	#Init the OnLoad event to correct the initial state of the form
    	$form1.add_Load($Form_StateCorrection_Load)
    	#Clean up the control events
    	$form1.add_FormClosed($Form_Cleanup_FormClosed)
    	#Show the Form
    	return $form1.ShowDialog()
    
    } #End Function
    
    #Call the form
    Call-testcred_psf | Out-Null
    
    #34655

    ok, a little more info, i think i might know the difference. i am using powershell studio, if i export the gui script to ps1 file, and run that, the connections and messages all show up in the powershell window used to call the gui script.

    however, to ease use, i am building them out to .exe

    when built as an exe, and the connection occurs is where the pop-ups come from

    #34659
    Profile photo of Dan Potter
    Dan Potter
    Participant

    I built this form in Powershell Studio. What build options are you using? I have ps version 5 (windows forms) x64 in STA mode.

    Still no prompts.

    Does the MSOnline module show up in the object browser in the left bottom pane?

    #34667

    yes msonline does show up in the object browser.

    the platform is sapien powershell v5 host (windows) x64 without sta mode checked.

    #34668

    well, that answers that question, how strange.

    i guess could anyone explain the difference between windows and windows forms?

    once i changed to windows the pop-pus did not occur

    #34719
    Profile photo of Dan Potter
    Dan Potter
    Participant

    Honestly I don't know the difference between windows and windows forms. I actually only use sapien for forms so I leave it on (windows forms) permanently.

    I hadn't actually noticed the plain (windows) before.

    Here's a better place to ask. https://www.sapien.com/forums/index.php

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.