Merge branch 'main' of https://git.azuze.fr/kawa/ps-scripts
This commit is contained in:
commit
09d5e0f281
|
@ -12,6 +12,17 @@
|
||||||
# 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
|
||||||
|
@ -387,35 +398,43 @@ $FMain.Text = "SharePoint Utils GUI"
|
||||||
##Lister les sites dans les comboBoxes
|
##Lister les sites dans les comboBoxes
|
||||||
#### On lance le ScriptBlock dans un runspace au clic du bouton BlistSites
|
#### On lance le ScriptBlock dans un runspace au clic du bouton BlistSites
|
||||||
$BlistSites.Add_Click({
|
$BlistSites.Add_Click({
|
||||||
# On vide la variable pnpConnection pour ne pas avoir de faux positifs
|
$newRunspace =[runspacefactory]::CreateRunspace()
|
||||||
$pnpConnection = $Null
|
$newRunspace.ApartmentState ="STA"
|
||||||
|
$newRunspace.ThreadOptions ="ReuseThread"
|
||||||
|
$newRunspace.Open()
|
||||||
|
$newRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
|
||||||
|
|
||||||
# On stocke la dernière connexion PnP
|
$BlistSitesRunSpace = [PowerShell]::Create().AddScript({
|
||||||
$pnpConnection = Get-PnPConnection | Out-String
|
|
||||||
|
|
||||||
# À améliorer, mais pour l'instant, ça devrait passer
|
#On vide la variable pnpConnection pour ne pas avoir de faux positifs
|
||||||
if (-not ([string]::IsNullOrEmpty($pnpConnection))) {
|
$pnpConnection=$Null
|
||||||
$CBdestSite.Items.Clear()
|
#On stocke la derniere connection PnP
|
||||||
$CBsourceSite.Items.Clear()
|
$pnpConnection = Get-PnPConnection | Out-string
|
||||||
$sitesList = Get-PnPTenantSite | Where-Object -Property Template -NotIn (
|
#A ameliorer, mais pour l'instant, ca devrait passer
|
||||||
"SRCHCEN#0", "REDIRECTSITE#0", "SPSMSITEHOST#0", "APPCATALOG#0",
|
if(-not ([string]::IsNullOrEmpty($pnpConnection))){
|
||||||
"POINTPUBLISHINGHUB#0", "EDISC#0", "STS#-1", 'EHS#1', 'POINTPUBLISHINGTOPIC#0'
|
$CBdestSite.Items.Clear()
|
||||||
) | Select-Object url
|
$CBsourceSite.Items.Clear()
|
||||||
|
$sitesList = $null
|
||||||
$LresultsMove.Items.Clear()
|
$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
|
||||||
foreach ($siteUrl in $sitesList) {
|
$LresultsMove.Items.Clear()
|
||||||
$siteUrl -match "@{Url=(?<content>.*)}"
|
foreach($siteUrl in $sitesList){
|
||||||
$siteUrlClean = $matches["content"]
|
$siteUrl -match "@{Url=(?<content>.*)}"
|
||||||
$CBsourceSite.Items.Add([string]$siteUrlClean)
|
$siteUrlClean = $matches["content"]
|
||||||
$CBdestSite.Items.Add([string]$siteUrlClean)
|
$CBsourceSite.Items.Add([string]$siteUrlClean)
|
||||||
}
|
$CBdestSite.Items.Add([string]$siteUrlClean)
|
||||||
} elseif ([string]::IsNullOrEmpty($pnpConnection)) {
|
}
|
||||||
$LresultsMove.Items.Clear()
|
}
|
||||||
$LresultsMove.Items.Add("Connectez-vous au tenant d'abord")
|
elseif(([string]::IsNullOrEmpty($pnpConnection))){
|
||||||
} 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()
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -434,6 +453,13 @@ $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]+)+)',''
|
||||||
|
@ -442,6 +468,9 @@ $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()
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -455,29 +484,38 @@ $tenantURL = $URLTenant.Text
|
||||||
$BconnectSP.Add_Click({
|
$BconnectSP.Add_Click({
|
||||||
|
|
||||||
Disconnect-PnPOnline
|
Disconnect-PnPOnline
|
||||||
$Url = $ConnectSPUrl
|
$newRunspace =[runspacefactory]::CreateRunspace()
|
||||||
# Votre code de connexion à SharePoint ici
|
$newRunspace.ApartmentState ="STA"
|
||||||
Connect-PnPOnline -Url $Url -UseWebLogin
|
$newRunspace.ThreadOptions ="ReuseThread"
|
||||||
Switch ($ERROR)
|
$newRunspace.Open()
|
||||||
{
|
$newRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
|
||||||
{$ERROR[0] -match "Host not reachable" }{
|
|
||||||
$label4.Text = "Injoignable"
|
$connectToSPRunspace.PowerShell = [PowerShell]::Create().AddScript({
|
||||||
$label4.ForeColor = [System.Drawing.Color]::MediumVioletRed
|
Connect-PnPOnline -Url $tenantURL -Interactive | Out-String
|
||||||
Break}
|
|
||||||
{$ERROR[0] -match "User canceled authentication."}{
|
Switch ($ERROR)
|
||||||
$label4.Text = "Annulé"
|
{
|
||||||
$label4.ForeColor = [System.Drawing.Color]::MediumVioletRed
|
{$ERROR[0] -match "Host not reachable" }{
|
||||||
Break}
|
$label4.Text = "Injoignable"
|
||||||
{-not ([string]::IsNullOrEmpty($pnpConnection))}{
|
$label4.ForeColor = [System.Drawing.Color]::MediumVioletRed
|
||||||
$label4.Text = "Connecté"
|
Break}
|
||||||
$label4.ForeColor = [System.Drawing.Color]::Green
|
{$ERROR[0] -match "User canceled authentication."}{
|
||||||
|
$label4.Text = "Annulé"
|
||||||
|
$label4.ForeColor = [System.Drawing.Color]::MediumVioletRed
|
||||||
|
Break}
|
||||||
|
{-not ([string]::IsNullOrEmpty($pnpConnection))}{
|
||||||
|
$label4.Text = "Connecté"
|
||||||
|
$label4.ForeColor = [System.Drawing.Color]::Green
|
||||||
|
}
|
||||||
|
Default {
|
||||||
|
$label4.Text = "Connecté"
|
||||||
|
$label4.ForeColor = [System.Drawing.Color]::Green
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Default {
|
})
|
||||||
$label4.Text = "..."
|
$connectToSPRunspace.PowerShell.Runspace = $newRunspace
|
||||||
$label4.ForeColor = [System.Drawing.Color]::Gray
|
$connectToSPRunspace.Thread = $connectToSPRunspace.PowerShell.BeginInvoke()
|
||||||
}
|
})
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
function OnFormClosing_FMain{
|
function OnFormClosing_FMain{
|
||||||
|
|
Loading…
Reference in New Issue