Update
This commit is contained in:
		@@ -12,17 +12,6 @@
 | 
				
			|||||||
#  Source            : C:\Users\SebastienQUEROL\source\repos\sharepointmover-gui\Form1.Designer.cs
 | 
					#  Source            : C:\Users\SebastienQUEROL\source\repos\sharepointmover-gui\Form1.Designer.cs
 | 
				
			||||||
################################################################################
 | 
					################################################################################
 | 
				
			||||||
 | 
					
 | 
				
			||||||
###############Thread Setup
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$Global:syncHash = [hashtable]::Synchronized(@{})
 | 
					 | 
				
			||||||
$newRunspace =[runspacefactory]::CreateRunspace()
 | 
					 | 
				
			||||||
$newRunspace.ApartmentState ="STA"
 | 
					 | 
				
			||||||
$newRunspace.ThreadOptions ="ReuseThread"
 | 
					 | 
				
			||||||
$newRunspace.Open()
 | 
					 | 
				
			||||||
$newRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
###########################
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
##Aucune foutre idée de ce qu'est cense faire ce morceau de code, ca a été généré par le createur de forms
 | 
					##Aucune foutre idée de ce qu'est cense faire ce morceau de code, ca a été généré par le createur de forms
 | 
				
			||||||
# function Get-ScriptDirectory
 | 
					# function Get-ScriptDirectory
 | 
				
			||||||
# { #Return the directory name of this script
 | 
					# { #Return the directory name of this script
 | 
				
			||||||
@@ -32,9 +21,6 @@ $newRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
 | 
				
			|||||||
# $ScriptPath = Get-ScriptDirectory
 | 
					# $ScriptPath = Get-ScriptDirectory
 | 
				
			||||||
###
 | 
					###
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### Premier runspace, contien le programme dans sa totalité
 | 
					 | 
				
			||||||
$MainWindowGUI = [PowerShell]::Create().AddScript({
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Chargement des assemblies externes
 | 
					# Chargement des assemblies externes
 | 
				
			||||||
Add-Type -AssemblyName System.Windows.Forms
 | 
					Add-Type -AssemblyName System.Windows.Forms
 | 
				
			||||||
Add-Type -AssemblyName System.Drawing
 | 
					Add-Type -AssemblyName System.Drawing
 | 
				
			||||||
@@ -399,44 +385,37 @@ $FMain.Text = "SharePoint Utils GUI"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#Onglet Move
 | 
					#Onglet Move
 | 
				
			||||||
##Lister les sites dans les comboBoxes
 | 
					##Lister les sites dans les comboBoxes
 | 
				
			||||||
 | 
					#### On lance le ScriptBlock dans un runspace au clic du bouton BlistSites
 | 
				
			||||||
$BlistSites.Add_Click({
 | 
					$BlistSites.Add_Click({
 | 
				
			||||||
	$newRunspace =[runspacefactory]::CreateRunspace()
 | 
					    # On vide la variable pnpConnection pour ne pas avoir de faux positifs
 | 
				
			||||||
	$newRunspace.ApartmentState ="STA"
 | 
					    $pnpConnection = $Null
 | 
				
			||||||
	$newRunspace.ThreadOptions ="ReuseThread"
 | 
					 | 
				
			||||||
	$newRunspace.Open()
 | 
					 | 
				
			||||||
	$newRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$BlistSitesRunSpace = [PowerShell]::Create().AddScript({
 | 
					    # On stocke la dernière connexion PnP
 | 
				
			||||||
 | 
					    $pnpConnection = Get-PnPConnection | Out-String
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		#On vide la variable pnpConnection pour ne pas avoir de faux positifs
 | 
					    # À améliorer, mais pour l'instant, ça devrait passer
 | 
				
			||||||
		$pnpConnection=$Null
 | 
					    if (-not ([string]::IsNullOrEmpty($pnpConnection))) {
 | 
				
			||||||
		#On stocke la derniere connection PnP
 | 
					 | 
				
			||||||
		$pnpConnection = Get-PnPConnection | Out-string
 | 
					 | 
				
			||||||
		#A ameliorer, mais pour l'instant, ca devrait passer
 | 
					 | 
				
			||||||
		if(-not ([string]::IsNullOrEmpty($pnpConnection))){
 | 
					 | 
				
			||||||
        $CBdestSite.Items.Clear()
 | 
					        $CBdestSite.Items.Clear()
 | 
				
			||||||
        $CBsourceSite.Items.Clear()
 | 
					        $CBsourceSite.Items.Clear()
 | 
				
			||||||
			$sitesList = $null
 | 
					        $sitesList = Get-PnPTenantSite | Where-Object -Property Template -NotIn (
 | 
				
			||||||
			$sitesList = Get-PnPTenantSite | Where-Object -Property Template -NotIn ("SRCHCEN#0", "REDIRECTSITE#0", "SPSMSITEHOST#0", "APPCATALOG#0", "POINTPUBLISHINGHUB#0", "EDISC#0", "STS#-1", 'EHS#1','POINTPUBLISHINGTOPIC#0') | Select-Object url
 | 
					            "SRCHCEN#0", "REDIRECTSITE#0", "SPSMSITEHOST#0", "APPCATALOG#0",
 | 
				
			||||||
 | 
					            "POINTPUBLISHINGHUB#0", "EDISC#0", "STS#-1", 'EHS#1', 'POINTPUBLISHINGTOPIC#0'
 | 
				
			||||||
 | 
					        ) | Select-Object url
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $LresultsMove.Items.Clear()
 | 
					        $LresultsMove.Items.Clear()
 | 
				
			||||||
				foreach($siteUrl in $sitesList){
 | 
					        foreach ($siteUrl in $sitesList) {
 | 
				
			||||||
            $siteUrl -match "@{Url=(?<content>.*)}"
 | 
					            $siteUrl -match "@{Url=(?<content>.*)}"
 | 
				
			||||||
            $siteUrlClean = $matches["content"]
 | 
					            $siteUrlClean = $matches["content"]
 | 
				
			||||||
            $CBsourceSite.Items.Add([string]$siteUrlClean)
 | 
					            $CBsourceSite.Items.Add([string]$siteUrlClean)
 | 
				
			||||||
            $CBdestSite.Items.Add([string]$siteUrlClean)
 | 
					            $CBdestSite.Items.Add([string]$siteUrlClean)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
		}
 | 
					    } elseif ([string]::IsNullOrEmpty($pnpConnection)) {
 | 
				
			||||||
		elseif(([string]::IsNullOrEmpty($pnpConnection))){
 | 
					        $LresultsMove.Items.Clear()
 | 
				
			||||||
 | 
					        $LresultsMove.Items.Add("Connectez-vous au tenant d'abord")
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
        $LresultsMove.Items.Clear()
 | 
					        $LresultsMove.Items.Clear()
 | 
				
			||||||
        $LresultsMove.Items.Add("Connectez-vous au tenant d'abord")
 | 
					        $LresultsMove.Items.Add("Connectez-vous au tenant d'abord")
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
		else{
 | 
					 | 
				
			||||||
			$LresultsMove.Items.Clear()
 | 
					 | 
				
			||||||
			$LresultsMove.Items.Add("Connectez-vous au tenant d'abord")
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
	$BlistSitesRunSpace.PowerShell.Runspace = $newRunspace
 | 
					 | 
				
			||||||
    $BlistSitesRunSpace.Thread = $BlistSitesRunSpace.PowerShell.BeginInvoke()  
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -455,13 +434,6 @@ $BlistSites.Add_Click({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
$Bgo.Add_Click({
 | 
					$Bgo.Add_Click({
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	$newRunspace =[runspacefactory]::CreateRunspace()
 | 
					 | 
				
			||||||
	$newRunspace.ApartmentState ="STA"
 | 
					 | 
				
			||||||
	$newRunspace.ThreadOptions ="ReuseThread"
 | 
					 | 
				
			||||||
	$newRunspace.Open()
 | 
					 | 
				
			||||||
	$newRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	$copySPRunspace.PowerShell = [PowerShell]::Create().AddScript({
 | 
					 | 
				
			||||||
		$destSite = $CBdestSite.Text
 | 
							$destSite = $CBdestSite.Text
 | 
				
			||||||
		$sourceSite = $CBsourceSite.Text
 | 
							$sourceSite = $CBsourceSite.Text
 | 
				
			||||||
		$sourceSite = $sourceSite -Replace '[A-Za-z]+://([A-Za-z]+(\.[A-Za-z]+)+)',''
 | 
							$sourceSite = $sourceSite -Replace '[A-Za-z]+://([A-Za-z]+(\.[A-Za-z]+)+)',''
 | 
				
			||||||
@@ -470,9 +442,6 @@ $Bgo.Add_Click({
 | 
				
			|||||||
		$jobCopyPending = Copy-PnPFile -SourceUrl "$sourceSite" -TargetUrl "$destSite" -Force -OverwriteIfAlreadyExists
 | 
							$jobCopyPending = Copy-PnPFile -SourceUrl "$sourceSite" -TargetUrl "$destSite" -Force -OverwriteIfAlreadyExists
 | 
				
			||||||
		$jobStatus = Receive-PnPCopyMoveJobStatus -Job $jobCopyPending -Wait
 | 
							$jobStatus = Receive-PnPCopyMoveJobStatus -Job $jobCopyPending -Wait
 | 
				
			||||||
		Write-Output $jobStatus
 | 
							Write-Output $jobStatus
 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
	$copySPRunspace.PowerShell.Runspace = $newRunspace
 | 
					 | 
				
			||||||
	$copySPRunspace.Thread = $copySPRunspace.PowerShell.BeginInvoke()  
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -484,16 +453,11 @@ $pnpConnection = Get-PnPConnection | Out-string
 | 
				
			|||||||
$tenantURL = $URLTenant.Text
 | 
					$tenantURL = $URLTenant.Text
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$BconnectSP.Add_Click({
 | 
					$BconnectSP.Add_Click({
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	Disconnect-PnPOnline
 | 
						Disconnect-PnPOnline
 | 
				
			||||||
	$newRunspace =[runspacefactory]::CreateRunspace()
 | 
						$Url = $ConnectSPUrl
 | 
				
			||||||
	$newRunspace.ApartmentState ="STA"
 | 
					    # Votre code de connexion à SharePoint ici
 | 
				
			||||||
	$newRunspace.ThreadOptions ="ReuseThread"
 | 
					    Connect-PnPOnline -Url $Url -UseWebLogin
 | 
				
			||||||
	$newRunspace.Open()
 | 
					 | 
				
			||||||
	$newRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	$connectToSPRunspace.PowerShell = [PowerShell]::Create().AddScript({
 | 
					 | 
				
			||||||
		Connect-PnPOnline -Url $tenantURL -Interactive | Out-String
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
	Switch ($ERROR)
 | 
						Switch ($ERROR)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	{$ERROR[0] -match "Host not reachable" }{ 
 | 
						{$ERROR[0] -match "Host not reachable" }{ 
 | 
				
			||||||
@@ -509,14 +473,11 @@ $BconnectSP.Add_Click({
 | 
				
			|||||||
		$label4.ForeColor = [System.Drawing.Color]::Green
 | 
							$label4.ForeColor = [System.Drawing.Color]::Green
 | 
				
			||||||
		}	
 | 
							}	
 | 
				
			||||||
	Default {
 | 
						Default {
 | 
				
			||||||
			$label4.Text = "Connecté"
 | 
							$label4.Text = "..."
 | 
				
			||||||
			$label4.ForeColor = [System.Drawing.Color]::Green
 | 
							$label4.ForeColor = [System.Drawing.Color]::Gray
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	})
 | 
					})
 | 
				
			||||||
	$connectToSPRunspace.PowerShell.Runspace = $newRunspace
 | 
					 | 
				
			||||||
	$connectToSPRunspace.Thread = $connectToSPRunspace.PowerShell.BeginInvoke() 
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function OnFormClosing_FMain{ 
 | 
					function OnFormClosing_FMain{ 
 | 
				
			||||||
@@ -533,6 +494,9 @@ function OnFormClosing_FMain{
 | 
				
			|||||||
$FMain.Add_FormClosing({ 
 | 
					$FMain.Add_FormClosing({ 
 | 
				
			||||||
	#Disconnect-PnPOnline
 | 
						#Disconnect-PnPOnline
 | 
				
			||||||
	Write-Host "Goodbye, come again soon :*"
 | 
						Write-Host "Goodbye, come again soon :*"
 | 
				
			||||||
 | 
						$RunspacePool.Close()
 | 
				
			||||||
 | 
						$RunspacePool.Dispose()
 | 
				
			||||||
 | 
						[gc]::Collect()
 | 
				
			||||||
	OnFormClosing_FMain
 | 
						OnFormClosing_FMain
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -540,8 +504,3 @@ $FMain.Add_Shown({$FMain.Activate()})
 | 
				
			|||||||
$ModalResult=$FMain.ShowDialog()
 | 
					$ModalResult=$FMain.ShowDialog()
 | 
				
			||||||
# Libération de la Form
 | 
					# Libération de la Form
 | 
				
			||||||
$FMain.Dispose()
 | 
					$FMain.Dispose()
 | 
				
			||||||
 | 
					 | 
				
			||||||
})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$MainWindowGUI.Runspace = $newRunspace
 | 
					 | 
				
			||||||
$data = $MainWindowGUI.BeginInvoke()
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user