-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsp_upload_#1.ps1
More file actions
94 lines (82 loc) · 3.74 KB
/
sp_upload_#1.ps1
File metadata and controls
94 lines (82 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Variablenkonfiguration
$User = "sascha.gibson@beta-hilfen.de" # Benutzername für SharePoint
$PasswordPlainText = "xxxxxx" # Passwort
$siteUrl = "https://betahilfen.sharepoint.com" # URL SharePoint-Site
$relativeUrl = "/sites/TEAM-BETA/Freigegebene Dokumente/Forms" # Relativer Pfad zur Bibliothek
$localFolderPath = "C:\Tools\test" # Lokaler Ordnerpfad
$maxRetryCount = 3 # Maximale Anzahl von Wiederholungsversuchen
$logFilePath = "c:\tools\upload_log.txt" # Pfad zur Log-Datei
$timeoutInMilliSeconds = 43200000 # 12 Stunden in Millisekunden
# Module prüfen und ggf. aktualisieren
$moduleNames = @("Microsoft.Online.SharePoint.PowerShell", "SharePointPnPPowerShellOnline") # Namen der Module
foreach ($moduleName in $moduleNames) {
# Prüfen, ob das Modul bereits installiert ist
$installedModule = Get-InstalledModule -Name $moduleName -ErrorAction SilentlyContinue
# Suchen nach der neuesten Version des Moduls im Repository
$latestModule = Find-Module -Name $moduleName
if ($installedModule -and $latestModule) {
# Vergleichen der Versionen
if ($installedModule.Version -lt $latestModule.Version) {
# Installieren der neuesten Version, wenn die installierte Version älter ist
Install-Module -Name $moduleName -Force -Scope CurrentUser
Write-Host "Modul $moduleName aktualisiert auf Version $($latestModule.Version)"
} else {
Write-Host "Die aktuellste Version von $moduleName ($($installedModule.Version)) ist bereits installiert."
}
} elseif ($latestModule) {
# Installieren des Moduls, wenn es noch nicht installiert ist
Install-Module -Name $moduleName -Scope CurrentUser
Write-Host "Modul $moduleName installiert in Version $($latestModule.Version)"
} else {
Write-Host "Modul $moduleName konnte nicht gefunden werden."
}
}
# Benutzeranmeldeinformationen konvertieren
$Password = ConvertTo-SecureString $PasswordPlainText -AsPlainText -Force
$Creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $Password
# Verbindungsaufbau zu SharePoint
Connect-PnPOnline -Url $siteUrl -Credentials $Creds -RequestTimeout $timeoutInMilliSeconds
# Log-Funktion
function Write-Log {
param (
[string]$Message
)
Add-Content -Path $logFilePath -Value "$(Get-Date) - $Message"
}
# Datei-Upload-Funktion mit Wiederholungslogik
function Upload-File {
param (
[string]$filePath,
[string]$sharePointPath,
[int]$retryCount = 0
)
try {
Add-PnPFile -Path $filePath -Folder $sharePointPath
Write-Host "Datei hochgeladen: $filePath"
} catch {
Write-Log "Fehler beim Hochladen der Datei: $filePath - $_"
if ($retryCount -lt $maxRetryCount) {
Start-Sleep -Seconds 5 # Kurze Pause vor dem Wiederholungsversuch
Upload-File -filePath $filePath -sharePointPath $sharePointPath -retryCount ($retryCount + 1)
} else {
Write-Log "Maximale Wiederholungsversuche erreicht für: $filePath"
}
}
}
# Funktion zum Hochladen eines Ordners
function Upload-Folder {
param (
[string]$localPath,
[string]$sharePointPath
)
# Durchsuchen des lokalen Ordners
Get-ChildItem -Path $localPath -Recurse | ForEach-Object {
if (!$_.PSIsContainer) {
$relativeFilePath = $_.FullName.Substring($localFolderPath.Length + 1)
$sharePointFilePath = "$sharePointPath/$relativeFilePath"
Upload-File -filePath $_.FullName -sharePointPath $sharePointFilePath
}
}
}
# Ordnerstruktur hochladen
Upload-Folder -localPath $localFolderPath -sharePointPath $relativeUrl