Add a script for installing windows

This commit is contained in:
Manuel Thalmann 2023-06-16 20:24:22 +02:00
parent dfdb288f1e
commit 1c312baa6e
4 changed files with 35 additions and 1 deletions

View file

@ -0,0 +1,4 @@
. "$PSScriptRoot/Manage.ps1";
Invoke-WindowsRestore;

View file

@ -28,3 +28,21 @@ function Invoke-WindowsBackup([Context] $context) {
Invoke-BackupVisualStudio $context;
$context.Backup($backupRoot, "$backupRoot.7z", @("-sdel"));
}
function Invoke-WindowsRestore() {
function Read-Path()
{
$backupPath = Read-Host -Prompt "Please enter the path to the archive load the backup from.";
if (-not (Test-Path -PathType Leaf $backupPath))
{
Write-Host "No file could be found at the specified path.";
return Read-Path;
}
}
$backupPath = Read-Path;
$context = [Context]::new();
$context.BackupName = "PortValhalla";
$context.Restore($backupPath, $context.BackupRoot());
}

View file

@ -9,7 +9,7 @@ foreach ($module in @("PSWindowsUpdate"))
Import-Module PSWindowsUpdate;
Import-Module ScheduledTasks;
$installerPath = "$PSScriptRoot/Manage.ps1";
$installerPath = "$PSScriptRoot/Install.ps1";
$setupPath = "$($MyInvocation.MyCommand.Path)";
Install-WindowsUpdate -AcceptAll -IgnoreReboot;

View file

@ -33,4 +33,16 @@ class Context {
-Wait `
-NoNewWindow;
}
[void] Restore([string]$archivePath, [string]$destinationPath) {
if (-not (Test-Path -PathType Container $destinationPath)) {
New-Item -ItemType Directory "$destinationPath";
}
Start-Process -WorkingDirectory "$destinationPath" `
-FilePath "7z"
-ArgumentList "x" `
-Wait `
-NoNewWindow;
}
}