Skip to content

Added PS1 file#13

Open
dabeersboys wants to merge 1 commit into
Nightmare-Eclipse:mainfrom
dabeersboys:main
Open

Added PS1 file#13
dabeersboys wants to merge 1 commit into
Nightmare-Eclipse:mainfrom
dabeersboys:main

Conversation

@dabeersboys
Copy link
Copy Markdown

@dabeersboys dabeersboys commented May 15, 2026

This file will create/rebuild the USB for Yellow Key if the FsTx directory is at the root of C:\
*Run Powershell as Admin.

This file will create the USB for Yellow Key
Copy link
Copy Markdown

@Macko62 Macko62 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-FsTx-To-SVI.ps1

Run as Administrator

─── Admin check ────────────────────────────────────────────────────────────

$isAdmin = ([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

if (-not $isAdmin) {
Write-Host "Please run this script as Administrator." -ForegroundColor Red
Read-Host "Press Enter to exit"
exit
}

─── Source check ───────────────────────────────────────────────────────────

$localSource = "C:\FsTx"

if (-not (Test-Path $localSource)) {
Write-Host "Source folder not found: $localSource" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit
}

─── Mode selection ─────────────────────────────────────────────────────────

Write-Host ""
Write-Host "Choose an option:" -ForegroundColor Cyan
Write-Host "1. New drive"
Write-Host "2. Rebuild drive"

$mode = Read-Host "Enter 1 or 2"

if ($mode -notin @("1", "2")) {
Write-Host "Invalid option." -ForegroundColor Red
Read-Host "Press Enter to exit"
exit
}

─── Drive selection ─────────────────────────────────────────────────────────

Write-Host ""
Write-Host "Available drives:" -ForegroundColor Cyan
Get-PSDrive -PSProvider FileSystem | Select-Object Name, Root, Description
Write-Host ""

$rawInput = Read-Host "Enter the USB drive letter only, for example E"
$driveLetter = $rawInput.Trim().TrimEnd(":").Substring(0, 1).ToUpper()

Validate: must be a single letter

if ($driveLetter -notmatch "^[A-Z]$") {
Write-Host "Invalid drive letter: '$rawInput'" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit
}

Block system drive

if ($driveLetter -eq "C") {
Write-Host "Drive C: is not allowed (system drive)." -ForegroundColor Red
Read-Host "Press Enter to exit"
exit
}

$usbRoot = "$driveLetter`:"
$sviDir = Join-Path $usbRoot "System Volume Information"
$destDir = Join-Path $sviDir "FsTx"

if (-not (Test-Path $usbRoot)) {
Write-Host "Drive $usbRoot does not exist." -ForegroundColor Red
Read-Host "Press Enter to exit"
exit
}

─── SVI folder ─────────────────────────────────────────────────────────────

if (-not (Test-Path $sviDir)) {
Write-Host "System Volume Information folder not found. Creating it..." -ForegroundColor Yellow
New-Item -ItemType Directory -Path $sviDir -Force | Out-Null
}

─── Permissions ─────────────────────────────────────────────────────────────

Write-Host ""
Write-Host "Taking ownership of System Volume Information..." -ForegroundColor Cyan

/D expects "Y" on English Windows, "O" on French Windows — detect automatically

$uiLang = (Get-Culture).TwoLetterISOLanguageName
$yesParam = if ($uiLang -eq "fr") { "O" } else { "Y" }

takeown /F "$sviDir" /R /D $yesParam | Out-Null

if ($LASTEXITCODE -ne 0) {
Write-Host "takeown failed (exit code $LASTEXITCODE). Aborting." -ForegroundColor Red
Read-Host "Press Enter to exit"
exit
}

Write-Host ""
Write-Host "Granting Administrators full control..." -ForegroundColor Cyan

Resolve the local Administrators group name via its built-in SID (works on any language)

$adminSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544")
$adminGroup = $adminSID.Translate([System.Security.Principal.NTAccount]).Value

Translate returns "BUILTIN\Administrateurs" or "BUILTIN\Administrators" etc.

icacls only needs the part after the backslash

$adminName = $adminGroup.Split("")[1]

icacls "$sviDir" /grant "${adminName}:F" /T /C | Out-Null

if ($LASTEXITCODE -ne 0) {
Write-Host "icacls failed (exit code $LASTEXITCODE). Aborting." -ForegroundColor Red
Read-Host "Press Enter to exit"
exit
}

─── Copy logic ──────────────────────────────────────────────────────────────

if ($mode -eq "1") {
if (Test-Path $destDir) {
Write-Host ""
Write-Host "FsTx already exists on this drive:" -ForegroundColor Red
Write-Host " $destDir"
Write-Host "Use the rebuild option (2) if you want to replace it."
Read-Host "Press Enter to exit"
exit
}

Write-Host ""
Write-Host "Copying FsTx from C:\ to System Volume Information..." -ForegroundColor Cyan
Copy-Item -Path $localSource -Destination $sviDir -Recurse -Force

}

if ($mode -eq "2") {
if (Test-Path $destDir) {
Write-Host ""
Write-Host "Removing existing FsTx from System Volume Information..." -ForegroundColor Yellow
Remove-Item -Path $destDir -Recurse -Force
} else {
Write-Host ""
Write-Host "No existing FsTx folder found. Continuing with fresh copy..." -ForegroundColor Yellow
}

Write-Host ""
Write-Host "Copying fresh FsTx from C:\ to System Volume Information..." -ForegroundColor Cyan
Copy-Item -Path $localSource -Destination $sviDir -Recurse -Force

}

─── Result check ─────────────────────────────────────────────────────────────

Write-Host ""

if (Test-Path $destDir) {
Write-Host "Done." -ForegroundColor Green
Write-Host "Source : $localSource"
Write-Host "Destination : $destDir"
} else {
Write-Host "Copy appears to have failed: destination not found." -ForegroundColor Red
Write-Host " Expected : $destDir"
}

Read-Host "Press Enter to exit"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants