Add Add_CLick function for the connexion button

This commit is contained in:
Sébastien QUEROL 2024-03-09 16:16:00 +01:00
parent 54ee71c7f2
commit 8b50ddb79c
2 changed files with 53 additions and 20 deletions

View File

@ -0,0 +1,3 @@
# SharePoint Utils
Sharepoint Utils concatenate all the useful scripts useed to manage your SharePoints in one easy to use GUI.

View File

@ -42,7 +42,7 @@ $tabs = New-Object System.Windows.Forms.TabControl
$tabPage1 = New-Object System.Windows.Forms.TabPage $tabPage1 = New-Object System.Windows.Forms.TabPage
$tabPage2 = New-Object System.Windows.Forms.TabPage $tabPage2 = New-Object System.Windows.Forms.TabPage
$BconnectSP = New-Object System.Windows.Forms.Button $BconnectSP = New-Object System.Windows.Forms.Button
$textBox1 = New-Object System.Windows.Forms.TextBox $URLTenant = New-Object System.Windows.Forms.TextBox
$label3 = New-Object System.Windows.Forms.Label $label3 = New-Object System.Windows.Forms.Label
$groupBox1 = New-Object System.Windows.Forms.GroupBox $groupBox1 = New-Object System.Windows.Forms.GroupBox
$groupBox2 = New-Object System.Windows.Forms.GroupBox $groupBox2 = New-Object System.Windows.Forms.GroupBox
@ -100,19 +100,19 @@ $Bgo.UseVisualStyleBackColor = $true
# #
# CBsourceSite # CBsourceSite
# #
$comboBox1.FormattingEnabled = $true $CBsourceSite.FormattingEnabled = $true
$comboBox1.Location = New-Object System.Drawing.Point(23, 44) $CBsourceSite.Location = New-Object System.Drawing.Point(23, 44)
$comboBox1.Name = "comboBox1" $CBsourceSite.Name = "CBsourceSite"
$comboBox1.Size = New-Object System.Drawing.Size(587, 21) $CBsourceSite.Size = New-Object System.Drawing.Size(587, 21)
$comboBox1.TabIndex = 2 $CBsourceSite.TabIndex = 2
# #
# CBdestSite # CBdestSite
# #
$comboBox2.FormattingEnabled = $true $CBdestSite.FormattingEnabled = $true
$comboBox2.Location = New-Object System.Drawing.Point(23, 113) $CBdestSite.Location = New-Object System.Drawing.Point(23, 113)
$comboBox2.Name = "comboBox2" $CBdestSite.Name = "CBdestSite"
$comboBox2.Size = New-Object System.Drawing.Size(587, 21) $CBdestSite.Size = New-Object System.Drawing.Size(587, 21)
$comboBox2.TabIndex = 3 $CBdestSite.TabIndex = 3
# #
# progressBar1 # progressBar1
# #
@ -161,8 +161,8 @@ $tabPage1.Controls.Add($label1)
$tabPage1.Controls.Add($progressBar1) $tabPage1.Controls.Add($progressBar1)
$tabPage1.Controls.Add($label2) $tabPage1.Controls.Add($label2)
$tabPage1.Controls.Add($Bgo) $tabPage1.Controls.Add($Bgo)
$tabPage1.Controls.Add($comboBox1) $tabPage1.Controls.Add($CBsourceSite)
$tabPage1.Controls.Add($comboBox2) $tabPage1.Controls.Add($CBdestSite)
$tabPage1.Location = New-Object System.Drawing.Point(4, 22) $tabPage1.Location = New-Object System.Drawing.Point(4, 22)
$tabPage1.Name = "tabPage1" $tabPage1.Name = "tabPage1"
$tabPage1.Padding = New-Object System.Windows.Forms.Padding(3) $tabPage1.Padding = New-Object System.Windows.Forms.Padding(3)
@ -193,12 +193,13 @@ $BconnectSP.TabIndex = 0
$BconnectSP.Text = "Connexion" $BconnectSP.Text = "Connexion"
$BconnectSP.UseVisualStyleBackColor = $true $BconnectSP.UseVisualStyleBackColor = $true
# #
# textBox1 # URLTenant
# #
$textBox1.Location = New-Object System.Drawing.Point(22, 55) $URLTenant.Location = New-Object System.Drawing.Point(22, 55)
$textBox1.Name = "textBox1" $URLTenant.Name = "URLTenant"
$textBox1.Size = New-Object System.Drawing.Size(325, 20) $URLTenant.Text = "https://perlinpimpim-admin.sharepoint.com"
$textBox1.TabIndex = 1 $URLTenant.Size = New-Object System.Drawing.Size(325, 20)
$URLTenant.TabIndex = 1
# #
# label3 # label3
# #
@ -215,7 +216,7 @@ $label3.Text = "URL du tenant SharePoint"
$groupBox1.Controls.Add($label4) $groupBox1.Controls.Add($label4)
$groupBox1.Controls.Add($label3) $groupBox1.Controls.Add($label3)
$groupBox1.Controls.Add($BconnectSP) $groupBox1.Controls.Add($BconnectSP)
$groupBox1.Controls.Add($textBox1) $groupBox1.Controls.Add($URLTenant)
$groupBox1.Location = New-Object System.Drawing.Point(8, 6) $groupBox1.Location = New-Object System.Drawing.Point(8, 6)
$groupBox1.Name = "groupBox1" $groupBox1.Name = "groupBox1"
$groupBox1.Size = New-Object System.Drawing.Size(473, 100) $groupBox1.Size = New-Object System.Drawing.Size(473, 100)
@ -353,7 +354,36 @@ $FMain.Controls.Add($menuStrip1)
$FMain.ForeColor = [System.Drawing.Color]::Black $FMain.ForeColor = [System.Drawing.Color]::Black
$FMain.MainMenuStrip = $menuStrip1 $FMain.MainMenuStrip = $menuStrip1
$FMain.Name = "FMain" $FMain.Name = "FMain"
$FMain.Text = "SharePoint Manager GUI" $FMain.Text = "SharePoint Utils GUI"
$BconnectSP.Add_Click({
$tenantURL = $URLTenant.Text
$ConnResult = Connect-PnPOnline -Url $tenantURL -Interactive | Out-String
Write-Host $ConnResult
$ConnBool = $ConnResult -contains "Host not reachable"
if($ConnBool = $true)
{
$label4.Text = "Injoignable"
}
else{
$ConnBool = $ConnResult -contains "User canceled authentication."
if($ConnBool = $true)
{
$label4.Text = "Déconnecté"
}
else{
$label4.ForeColor = [System.Drawing.Color]::Green
$label4.Text = "Connecté"
}
}
})
function OnFormClosing_FMain{ function OnFormClosing_FMain{
# $this parameter is equal to the sender (object) # $this parameter is equal to the sender (object)