Complete change of direction, now the form is made with VS 2022's WPF form builder and converted into a PS1 script with ConvertForm. Neat.

This commit is contained in:
Kawawete 2024-03-07 21:14:50 +01:00
parent 327bf76a52
commit 8509174d91
5 changed files with 167 additions and 112 deletions

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,14 @@
20240307 08:51:28: ForEach-Object: C:\Users\SebastienQUEROL\git.azuze.fr\ps-scripts\Sharepoint\gui\spmover\Functions.ps1:43:31 Line | 43 | $Xml.Attributes | ForEach-Object { | ~~~~~~~~~~~~~~~~ | Exception setting "Image": "Cannot convert the "System.Drawing.Bitmap" value of type "System.String" to type "System.Drawing.Image"."
20240307 09:27:01: New-Object: C:\Users\SebastienQUEROL\git.azuze.fr\ps-scripts\Sharepoint\gui\spmover\Functions.ps1:33:71 Line | 33 | … ) {$newControl = New-Object System.Windows.Forms.$($Xml.ToString())} | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Cannot find type [System.Windows.Forms.Image]: verify that the assembly containing this type is loaded.
20240307 09:28:50: New-Object: C:\Users\SebastienQUEROL\git.azuze.fr\ps-scripts\Sharepoint\gui\spmover\Functions.ps1:33:71 Line | 33 | … ) {$newControl = New-Object System.Windows.Forms.$($Xml.ToString())} | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Cannot find type [System.Windows.Forms.Image]: verify that the assembly containing this type is loaded.
20240307 09:34:41: ForEach-Object: C:\Users\SebastienQUEROL\git.azuze.fr\ps-scripts\Sharepoint\gui\spmover\Functions.ps1:43:31 Line | 43 | $Xml.Attributes | ForEach-Object { | ~~~~~~~~~~~~~~~~ | Exception setting "Image": "Cannot convert the "System.Drawing.Bitmap" value of type "System.String" to type "System.Drawing.Image"."
20240307 09:34:53: ForEach-Object: C:\Users\SebastienQUEROL\git.azuze.fr\ps-scripts\Sharepoint\gui\spmover\Functions.ps1:43:31 Line | 43 | $Xml.Attributes | ForEach-Object { | ~~~~~~~~~~~~~~~~ | Exception setting "Image": "Cannot convert the "System.Drawing.Bitmap" value of type "System.String" to type "System.Drawing.Image"."
20240307 09:38:58: ForEach-Object: C:\Users\SebastienQUEROL\git.azuze.fr\ps-scripts\Sharepoint\gui\spmover\Functions.ps1:43:31 Line | 43 | $Xml.Attributes | ForEach-Object { | ~~~~~~~~~~~~~~~~ | Exception setting "Image": "Cannot convert the "System.Drawing.Bitmap" value of type "System.String" to type "System.Drawing.Image"."
20240307 09:40:53: ForEach-Object: C:\Users\SebastienQUEROL\git.azuze.fr\ps-scripts\Sharepoint\gui\spmover\Functions.ps1:43:31 Line | 43 | $Xml.Attributes | ForEach-Object { | ~~~~~~~~~~~~~~~~ | Exception setting "Image": "Cannot convert the "System.Drawing.Bitmap" value of type "System.String" to type "System.Drawing.Image"."
20240307 09:41:31: ForEach-Object: C:\Users\SebastienQUEROL\git.azuze.fr\ps-scripts\Sharepoint\gui\spmover\Functions.ps1:43:31 Line | 43 | $Xml.Attributes | ForEach-Object { | ~~~~~~~~~~~~~~~~ | Exception setting "Image": "Cannot convert the "System.Drawing.Image" value of type "System.String" to type "System.Drawing.Image"."
20240307 09:44:00: ForEach-Object: C:\Users\SebastienQUEROL\git.azuze.fr\ps-scripts\Sharepoint\gui\spmover\Functions.ps1:43:31 Line | 43 | $Xml.Attributes | ForEach-Object { | ~~~~~~~~~~~~~~~~ | Exception setting "Image": "Cannot convert the "System.Drawing.Bitmap" value of type "System.String" to type "System.Drawing.Image"."
20240307 09:44:41: ForEach-Object: C:\Users\SebastienQUEROL\git.azuze.fr\ps-scripts\Sharepoint\gui\spmover\Functions.ps1:43:31 Line | 43 | $Xml.Attributes | ForEach-Object { | ~~~~~~~~~~~~~~~~ | Exception setting "Image": "Cannot convert the "System.Drawing.Bitmap" value of type "System.String" to type "System.Drawing.Image"."
20240307 09:45:56: ForEach-Object: C:\Users\SebastienQUEROL\git.azuze.fr\ps-scripts\Sharepoint\gui\spmover\Functions.ps1:43:31 Line | 43 | $Xml.Attributes | ForEach-Object { | ~~~~~~~~~~~~~~~~ | Exception setting "Image": "Cannot convert the "System.Drawing.Bitmap" value of type "System.String" to type "System.Drawing.Image"."
20240307 09:47:04: ForEach-Object: C:\Users\SebastienQUEROL\git.azuze.fr\ps-scripts\Sharepoint\gui\spmover\Functions.ps1:43:31 Line | 43 | $Xml.Attributes | ForEach-Object { | ~~~~~~~~~~~~~~~~ | Exception setting "Image": "Cannot convert the "System.Drawing.Bitmap" value of type "System.String" to type "System.Drawing.Image"."
20240307 09:48:25: ForEach-Object: C:\Users\SebastienQUEROL\git.azuze.fr\ps-scripts\Sharepoint\gui\spmover\Functions.ps1:43:31 Line | 43 | $Xml.Attributes | ForEach-Object { | ~~~~~~~~~~~~~~~~ | Exception calling "Add" with "2" argument(s): "Item has already been added. Key in dictionary: 'lbl_byWho' Key being added: 'lbl_byWho'"
20240307 11:16:28: InvalidOperation: Line | 45 | $Script:refs['btn_Start'].Add_Click($eventSB['btn_Start'].Cli … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Cannot index into a null array.

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -1,124 +1,165 @@
<# ################################################################################
.NOTES #
=========================================================================== # Name : SharePoint Mover
FileName: spmover1.ps1 # Version : 0.1
Author: SebastienQUEROL # Author :
Created On: 2024/03/07 # Date : 07/03/2024
Last Updated: 2024/03/07 #
Organization: # Generated with ConvertForm module version 2.0.0
Version: v0.1 # PowerShell version 7.4.1
=========================================================================== #
# Invocation Line : Convert-Form -Path $Source -Destination $Destination -Encoding ascii -force
# Source : C:\Users\SebastienQUEROL\source\repos\sharepointmover-gui\Form1.Designer.cs
################################################################################
.DESCRIPTION function Get-ScriptDirectory
{ #Return the directory name of this script
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
.DEPENDENCIES $ScriptPath = Get-ScriptDirectory
#>
# ScriptBlock to Execute in STA Runspace # Chargement des assemblies externes
$sbGUI = {
param($BaseDir)
#region Environment Setup
try {
Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing Add-Type -AssemblyName System.Drawing
$FMain = New-Object System.Windows.Forms.Form
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered during Environment Setup."} $components = New-Object System.ComponentModel.Container
$menuStrip1 = New-Object System.Windows.Forms.MenuStrip
$Mconnexion = New-Object System.Windows.Forms.ToolStripMenuItem
$MConnexionSharepoint = New-Object System.Windows.Forms.ToolStripMenuItem
$Mquestion = New-Object System.Windows.Forms.ToolStripMenuItem
$MQuestionApropos = New-Object System.Windows.Forms.ToolStripMenuItem
$MQuestionWiki = New-Object System.Windows.Forms.ToolStripMenuItem
$Bgo = New-Object System.Windows.Forms.Button
$comboBox1 = New-Object System.Windows.Forms.ComboBox
$comboBox2 = New-Object System.Windows.Forms.ComboBox
$progressBar1 = New-Object System.Windows.Forms.ProgressBar
$sourceInfo = New-Object System.Windows.Forms.ToolTip($components)
$label1 = New-Object System.Windows.Forms.Label
$label2 = New-Object System.Windows.Forms.Label
#
# menuStrip1
#
$menuStrip1.Items.AddRange(@(
$Mconnexion,
$Mquestion))
$menuStrip1.Location = New-Object System.Drawing.Point(0, 0)
$menuStrip1.Name = "menuStrip1"
$menuStrip1.Size = New-Object System.Drawing.Size(800, 24)
$menuStrip1.TabIndex = 0
$menuStrip1.Text = "menuStrip1"
#
# Mconnexion
#
$Mconnexion.DropDownItems.AddRange(@(
$MConnexionSharepoint))
$Mconnexion.Name = "Mconnexion"
$Mconnexion.Size = New-Object System.Drawing.Size(77, 20)
$Mconnexion.Text = "Connexion"
#
# MConnexionSharepoint
#
$MConnexionSharepoint.CheckOnClick = $true
$MConnexionSharepoint.Name = "MConnexionSharepoint"
$MConnexionSharepoint.Size = New-Object System.Drawing.Size(131, 22)
$MConnexionSharepoint.Text = "Sharepoint"
#
# Mquestion
#
$Mquestion.DropDownItems.AddRange(@(
$MQuestionApropos,
$MQuestionWiki))
$Mquestion.Name = "Mquestion"
$Mquestion.Size = New-Object System.Drawing.Size(24, 20)
$Mquestion.Text = "?"
#
# MQuestionApropos
#
$MQuestionApropos.Name = "MQuestionApropos"
$MQuestionApropos.Size = New-Object System.Drawing.Size(131, 22)
$MQuestionApropos.Text = "A propos..."
#
# MQuestionWiki
#
$MQuestionWiki.Name = "MQuestionWiki"
$MQuestionWiki.Size = New-Object System.Drawing.Size(131, 22)
$MQuestionWiki.Text = "Wiki"
#
# Bgo
#
$Bgo.ForeColor = [System.Drawing.Color]::White
$Bgo.Location = New-Object System.Drawing.Point(688, 155)
$Bgo.Name = "Bgo"
$Bgo.Size = New-Object System.Drawing.Size(75, 23)
$Bgo.TabIndex = 1
$Bgo.Text = "GO"
$Bgo.UseVisualStyleBackColor = $true
#
# comboBox1
#
$comboBox1.ForeColor = [System.Drawing.Color]::White
$comboBox1.FormattingEnabled = $true
$comboBox1.Location = New-Object System.Drawing.Point(27, 131)
$comboBox1.Name = "comboBox1"
$comboBox1.Size = New-Object System.Drawing.Size(587, 21)
$comboBox1.TabIndex = 2
#
# comboBox2
#
$comboBox2.ForeColor = [System.Drawing.Color]::White
$comboBox2.FormattingEnabled = $true
$comboBox2.Location = New-Object System.Drawing.Point(27, 182)
$comboBox2.Name = "comboBox2"
$comboBox2.Size = New-Object System.Drawing.Size(587, 21)
$comboBox2.TabIndex = 3
#
# progressBar1
#
$progressBar1.Location = New-Object System.Drawing.Point(12, 345)
$progressBar1.Name = "progressBar1"
$progressBar1.Size = New-Object System.Drawing.Size(776, 23)
$progressBar1.TabIndex = 4
#
# label1
#
$label1.AutoSize = $true
$label1.Location = New-Object System.Drawing.Point(27, 112)
$label1.Name = "label1"
$label1.Size = New-Object System.Drawing.Size(62, 13)
$label1.TabIndex = 5
$label1.Text = "Site Source"
#
# label2
#
$label2.AutoSize = $true
$label2.Location = New-Object System.Drawing.Point(27, 166)
$label2.Name = "label2"
$label2.Size = New-Object System.Drawing.Size(81, 13)
$label2.TabIndex = 6
$label2.Text = "Site Destination"
#
# FMain
#
$FMain.BackColor = [System.Drawing.SystemColors]::ControlText
$FMain.ClientSize = New-Object System.Drawing.Size(800, 450)
$FMain.Controls.Add($label2)
$FMain.Controls.Add($label1)
$FMain.Controls.Add($progressBar1)
$FMain.Controls.Add($comboBox2)
$FMain.Controls.Add($comboBox1)
$FMain.Controls.Add($Bgo)
$FMain.Controls.Add($menuStrip1)
$FMain.ForeColor = [System.Drawing.Color]::Snow
$FMain.MainMenuStrip = $menuStrip1
$FMain.Name = "FMain"
$FMain.Text = "SharePoint Mover GUI"
#endregion Environment Setup
#region Dot Sourcing of files
$dotSourceDir = $BaseDir
. "$($dotSourceDir)\Functions.ps1"
. "$($dotSourceDir)\Events.ps1"
#endregion Dot Sourcing of files
#region Form Initialization $FMain.ShowDialog()
try {
ConvertFrom-WinFormsXML -Reference refs -Suppress -Xml @"
<Form Name="MainForm" Size="547, 462">
<TextBox Name="tbx_SiteURL" CharacterCasing="Lower" Location="44, 133" Size="374, 20" Text="adresse du site" />
<TextBox Name="tbx_SourceFolderURL" Location="43, 158" Size="169, 20" Text="Dossier source" />
<TextBox Name="tbx_TargetFolderURL" Location="255, 158" Size="165, 20" Text="Dossier de destination" />
<Button Name="btn_Start" Location="437, 134" Size="59, 43" Text="GO !" />
<Label Name="lbl_byWho" Font="Comic Sans MS, 12pt" Location="40, 86" Text="by squerol" />
<Label Name="lbl_arrow" Font="Wingdings, 26.25pt" Location="211, 151" Size="43, 32" Text="F" />
<ListBox Name="lbx_results" Font="Lucida Console, 11.25pt" HorizontalScrollbar="True" ItemHeight="15" Location="45, 207" ScrollAlwaysVisible="True" Size="448, 184" />
<PictureBox Name="pbx_logo" Image="System.Drawing.Bitmap" Location="41, 18" Size="465, 69" />
</Form>
"@
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered during Form Initialization."}
#endregion Form Initialization
#region Event Assignment
try {
$Script:refs['btn_Start'].Add_Click($eventSB['btn_Start'].Click)
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered during Event Assignment."}
#endregion Event Assignment
#region Other Actions Before ShowDialog
try {
Remove-Variable -Name eventSB
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered before ShowDialog."}
#endregion Other Actions Before ShowDialog
# Show the form
try {[void]$Script:refs['MainForm'].ShowDialog()} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered unexpectedly at ShowDialog."}
<#
#region Actions After Form Closed
try {
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered after Form close."}
#endregion Actions After Form Closed
#>
}
#region Start Point of Execution
# Initialize STA Runspace
$rsGUI = [Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace()
$rsGUI.ApartmentState = 'STA'
$rsGUI.ThreadOptions = 'ReuseThread'
$rsGUI.Open()
# Create the PSCommand, Load into Runspace, and BeginInvoke
$cmdGUI = [Management.Automation.PowerShell]::Create().AddScript($sbGUI).AddParameter('BaseDir',$PSScriptRoot)
$cmdGUI.RunSpace = $rsGUI
$handleGUI = $cmdGUI.BeginInvoke()
# Hide Console Window
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
[Console.Window]::ShowWindow([Console.Window]::GetConsoleWindow(), 0)
#Loop Until GUI Closure
while ( $handleGUI.IsCompleted -eq $false ) {Start-Sleep -Seconds 5}
# Dispose of GUI Runspace/Command
$cmdGUI.EndInvoke($handleGUI)
$cmdGUI.Dispose()
$rsGUI.Dispose()
Exit
#endregion Start Point of Execution