Refactor windows configuration script
This commit is contained in:
parent
1bbc61fcbf
commit
5ba6a48eac
4 changed files with 150 additions and 1 deletions
scripts/Windows/Scripts
19
scripts/Windows/Scripts/Registry.ps1
Normal file
19
scripts/Windows/Scripts/Registry.ps1
Normal 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;
|
||||
}
|
||||
}
|
8
scripts/Windows/Scripts/System.ps1
Normal file
8
scripts/Windows/Scripts/System.ps1
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue