132 lines
4.5 KiB
PowerShell
132 lines
4.5 KiB
PowerShell
<#
|
|
.NOTES
|
|
===========================================================================
|
|
FileName: spmover1.ps1
|
|
Author: SebastienQUEROL
|
|
Created On: 2024/03/06
|
|
Last Updated: 2024/03/06
|
|
Organization:
|
|
Version: v0.1
|
|
===========================================================================
|
|
|
|
.DESCRIPTION
|
|
|
|
.DEPENDENCIES
|
|
#>
|
|
|
|
# ScriptBlock to Execute in STA Runspace
|
|
$sbGUI = {
|
|
param($BaseDir)
|
|
|
|
#region Child Forms
|
|
|
|
$Script:childFormInfo = @{
|
|
'MainForm' = @{
|
|
XMLText = @"
|
|
<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, 0.9" Location="40, 86" Text="by squerol" />
|
|
<Label Name="lbl_arrow" Font="Wingdings, 1.5" Location="211, 151" Size="43, 32" Text="F" />
|
|
<ListBox Name="lbx_results" Font="Lucida Console, 0.8" HorizontalScrollbar="True" ItemHeight="15" Location="45, 207" ScrollAlwaysVisible="True" Size="448, 184" />
|
|
</Form>
|
|
"@
|
|
}
|
|
}
|
|
#endregion Child Forms
|
|
|
|
#region Dot Sourcing of files
|
|
|
|
$dotSourceDir = $BaseDir
|
|
|
|
. "$($dotSourceDir)\Functions.ps1"
|
|
. "$($dotSourceDir)\EnvSetup.ps1"
|
|
|
|
#endregion Dot Sourcing of files
|
|
|
|
#region Form Initialization
|
|
|
|
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, 0.8" Location="40, 86" Text="by squerol" />
|
|
<Label Name="lbl_arrow" Font="Wingdings, 1.5" Location="211, 151" Size="43, 32" Text="F" />
|
|
<ListBox Name="lbx_results" Font="Lucida Console, 0.8" HorizontalScrollbar="True" ItemHeight="15" Location="45, 207" ScrollAlwaysVisible="True" Size="448, 184" />
|
|
</Form>
|
|
"@
|
|
} catch {Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered during Form Initialization."}
|
|
|
|
#endregion Form Initialization
|
|
|
|
#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
|
|
|
|
|
|
|
|
$btn_Start.Add_Click({
|
|
|
|
connectSP($tbx_SiteURL.Text)
|
|
moveSP($tbx_SourceFolderURL.Text,$tbx_TargetFolderURL.Text)
|
|
|
|
}) |