Refactor windows configuration script

This commit is contained in:
Manuel Thalmann 2024-08-05 20:07:39 +02:00
parent 1bbc61fcbf
commit 5ba6a48eac
4 changed files with 150 additions and 1 deletions
scripts/Windows/Scripts

View file

@ -0,0 +1,19 @@
using namespace Microsoft.Win32;
$null = New-Module {
function Edit-DefaultUserKey {
param(
[scriptblock] $Action
)
$rootPath = "HKLM:\DefaultUser";
$regRootPath = $rootPath -replace "^(\w+):([\\/]|$)","`$1`$2";
$hivePath = "$env:SystemDrive\Users\Default\NTUSER.dat";
$null = & reg load $regRootPath $hivePath;
[RegistryKey] $root = Get-Item $rootPath;
& $Action -Key $root;
$root.Handle.Close();
[System.GC]::Collect();
& reg unload $regRootPath;
}
}

View file

@ -0,0 +1,8 @@
<#
.SYNOPSIS
Creates a new temporary directory.
#>
function New-TemporaryDirectory {
$path = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName());
New-Item -ItemType Directory $path;
}