From 006840669e42ebcc53f168954d52a463a889ba66 Mon Sep 17 00:00:00 2001 From: Ivo Oskamp Date: Fri, 20 Dec 2024 22:15:56 +0100 Subject: [PATCH] Upload files to "/" --- Start-Remote-task-updatescript.ps1 | 12 ++++++ updatescript.ps1 | 58 +++++++++++++++++++++++++++++ variables.ps1 | 8 ++++ ver20220805 | Bin 0 -> 1024 bytes 4 files changed, 78 insertions(+) create mode 100644 Start-Remote-task-updatescript.ps1 create mode 100644 updatescript.ps1 create mode 100644 variables.ps1 create mode 100644 ver20220805 diff --git a/Start-Remote-task-updatescript.ps1 b/Start-Remote-task-updatescript.ps1 new file mode 100644 index 0000000..554496c --- /dev/null +++ b/Start-Remote-task-updatescript.ps1 @@ -0,0 +1,12 @@ +#Load variables +. "C:\scripts\automatic-updates-static\Variables.ps1" + +$password = Get-Content "c:\scripts\automatic-updates-static\localpassword.txt" | ConvertTo-SecureString +$username = $taskusername +$credential = New-Object System.Management.Automation.PSCredential($username,$password) + +$computernames = ($servers) +foreach($computername in $computernames) +{ + Invoke-Command -ScriptBlock{Get-ScheduledTask -TaskName "Automatic-Updates-updatescript" | Start-ScheduledTask} -ComputerName $computername -Credential $credential +} diff --git a/updatescript.ps1 b/updatescript.ps1 new file mode 100644 index 0000000..4ec0916 --- /dev/null +++ b/updatescript.ps1 @@ -0,0 +1,58 @@ +Remove-Item -Path "c:\Scripts\automatic-updates\" -Recurse -Force +$Folder = 'c:\Scripts\automatic-updates' +if (Test-Path -Path $Folder) { +} else { + New-Item $Folder -itemType Directory +} +$Folder = 'c:\Scripts\automatic-updates-static\Zip' +if (Test-Path -Path $Folder) { +} else { + New-Item $Folder -itemType Directory +} +$Folder = 'c:\Scripts\automatic-updates-static\Zip\ZipFile' +if (Test-Path -Path $Folder) { +} else { + New-Item $Folder -itemType Directory +} +$Folder = 'c:\Scripts\automatic-updates-static\Zip\UnZipFiles' +if (Test-Path -Path $Folder) { +} else { + New-Item $Folder -itemType Directory +} + +$Url = "https://gitlab.fourit.cloud/Ivo/automatic-updates-v2/-/archive/main/automatic-updates-v2-main.zip" +#Get file name along with extension from url using Split-Path cmdlet +$DownloadZipFile = "c:\Scripts\automatic-updates-static\Zip\ZipFile\" + $(Split-Path -Path $Url -Leaf) +#Set destination folder path for unzip files +$ExtractPath = "c:\scripts\automatic-updates-static\zip\UnZipFiles\" + +#Ignore SSL error +add-type @" + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +"@ +[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy + + +#Use Invoke-WebRequest cmdlet for above url to save response body and create shell object +Invoke-WebRequest -Uri $Url -OutFile $DownloadZipFile +$ExtractShell = New-Object -ComObject Shell.Application +#PowerShell extract zip file items +$ExtractFiles = $ExtractShell.Namespace($DownloadZipFile).Items() +#Use ExtractFiles to copy extracted file to destination folder and start a process +$ExtractShell.NameSpace($ExtractPath).CopyHere($ExtractFiles) +Start-Process $ExtractPath + +$current_folder = "C:\Scripts\automatic-updates-static\Zip\UnZipFiles\automatic-updates-v2-main\*" +$new_folder = "C:\Scripts\automatic-updates" +Move-Item -Path $current_folder -Destination $new_folder +Get-ChildItem c:\scripts\automatic-updates-static\zip\UnZipFiles -Include *.* -Recurse | ForEach { $_.Delete()} +Get-ChildItem C:\Scripts\automatic-updates-static\Zip\ZipFile -Include *.* -Recurse | ForEach { $_.Delete()} +.\Start-Remote-task-updatescript.ps1 diff --git a/variables.ps1 b/variables.ps1 new file mode 100644 index 0000000..2811672 --- /dev/null +++ b/variables.ps1 @@ -0,0 +1,8 @@ +#Place this file in directory: C:\Scripts\automatic-updates-static +$userdomain = "domain name" +$taskusername = "username" #Service account for running scripts +$mailto = "mail-to@example.com" #Where the mail with update notification will be send to +$mailfrom = "mail-from@example.com" #Where the mail will be send from +$smtpserver = "some.smtpserver.com" +$mailusername = "mail-username@example.com" +#$servers = #List of servers to be updated after DC. Example = "cust-tst-ts01","cust-tst-ts02" \ No newline at end of file diff --git a/ver20220805 b/ver20220805 new file mode 100644 index 0000000000000000000000000000000000000000..06d7405020018ddf3cacee90fd4af10487da3d20 GIT binary patch literal 1024 ScmZQz7zLvtFd70QH3R?z00031 literal 0 HcmV?d00001