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
$tabPage2 = New-Object System.Windows.Forms.TabPage
$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
$groupBox1 = New-Object System.Windows.Forms.GroupBox
$groupBox2 = New-Object System.Windows.Forms.GroupBox
@ -100,19 +100,19 @@ $Bgo.UseVisualStyleBackColor = $true
#
# CBsourceSite
#
$comboBox1.FormattingEnabled = $true
$comboBox1.Location = New-Object System.Drawing.Point(23, 44)
$comboBox1.Name = "comboBox1"
$comboBox1.Size = New-Object System.Drawing.Size(587, 21)
$comboBox1.TabIndex = 2
$CBsourceSite.FormattingEnabled = $true
$CBsourceSite.Location = New-Object System.Drawing.Point(23, 44)
$CBsourceSite.Name = "CBsourceSite"
$CBsourceSite.Size = New-Object System.Drawing.Size(587, 21)
$CBsourceSite.TabIndex = 2
#
# CBdestSite
#
$comboBox2.FormattingEnabled = $true
$comboBox2.Location = New-Object System.Drawing.Point(23, 113)
$comboBox2.Name = "comboBox2"
$comboBox2.Size = New-Object System.Drawing.Size(587, 21)
$comboBox2.TabIndex = 3
$CBdestSite.FormattingEnabled = $true
$CBdestSite.Location = New-Object System.Drawing.Point(23, 113)
$CBdestSite.Name = "CBdestSite"
$CBdestSite.Size = New-Object System.Drawing.Size(587, 21)
$CBdestSite.TabIndex = 3
#
# progressBar1
#
@ -161,8 +161,8 @@ $tabPage1.Controls.Add($label1)
$tabPage1.Controls.Add($progressBar1)
$tabPage1.Controls.Add($label2)
$tabPage1.Controls.Add($Bgo)
$tabPage1.Controls.Add($comboBox1)
$tabPage1.Controls.Add($comboBox2)
$tabPage1.Controls.Add($CBsourceSite)
$tabPage1.Controls.Add($CBdestSite)
$tabPage1.Location = New-Object System.Drawing.Point(4, 22)
$tabPage1.Name = "tabPage1"
$tabPage1.Padding = New-Object System.Windows.Forms.Padding(3)
@ -193,12 +193,13 @@ $BconnectSP.TabIndex = 0
$BconnectSP.Text = "Connexion"
$BconnectSP.UseVisualStyleBackColor = $true
#
# textBox1
# URLTenant
#
$textBox1.Location = New-Object System.Drawing.Point(22, 55)
$textBox1.Name = "textBox1"
$textBox1.Size = New-Object System.Drawing.Size(325, 20)
$textBox1.TabIndex = 1
$URLTenant.Location = New-Object System.Drawing.Point(22, 55)
$URLTenant.Name = "URLTenant"
$URLTenant.Text = "https://perlinpimpim-admin.sharepoint.com"
$URLTenant.Size = New-Object System.Drawing.Size(325, 20)
$URLTenant.TabIndex = 1
#
# label3
#
@ -215,7 +216,7 @@ $label3.Text = "URL du tenant SharePoint"
$groupBox1.Controls.Add($label4)
$groupBox1.Controls.Add($label3)
$groupBox1.Controls.Add($BconnectSP)
$groupBox1.Controls.Add($textBox1)
$groupBox1.Controls.Add($URLTenant)
$groupBox1.Location = New-Object System.Drawing.Point(8, 6)
$groupBox1.Name = "groupBox1"
$groupBox1.Size = New-Object System.Drawing.Size(473, 100)
@ -353,7 +354,36 @@ $FMain.Controls.Add($menuStrip1)
$FMain.ForeColor = [System.Drawing.Color]::Black
$FMain.MainMenuStrip = $menuStrip1
$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{
# $this parameter is equal to the sender (object)