# Personal builds only under Aseprite's license. Guide: https://graal.codes/guides/get-aseprite-free # irm https://graal.codes/get/aseprite.ps1 | iex function Build-Aseprite { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # avoid PowerShell progress overhead on large downloads [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $Pinned = '1.3.18.6' # latest redirect excludes prereleases function Get-LatestVersion { try { $latest = 'https://github.com/aseprite/aseprite/releases/latest' if (Get-Command curl.exe -ErrorAction SilentlyContinue) { $u = curl.exe -fsLI -o NUL -w '%{url_effective}' $latest } else { $r = Invoke-WebRequest -UseBasicParsing -Method Head -Uri $latest $u = if ($r.BaseResponse.ResponseUri) { $r.BaseResponse.ResponseUri.AbsoluteUri } else { $r.BaseResponse.RequestMessage.RequestUri.AbsoluteUri } } if ("$u" -match '/tag/v(\d+(\.\d+)+)$') { return $matches[1] } } catch {} return $null } $AsepriteVersion = if ($env:ASEPRITE_VERSION) { $env:ASEPRITE_VERSION } else { Get-LatestVersion } $CMakeVersion = '3.31.6' $NinjaVersion = '1.12.1' $Work = $env:ASEPRITE_BUILD_DIR if (-not $Work) { $Work = Join-Path $env:LOCALAPPDATA 'aseprite-build' # short ASCII path for the compiler tools if ($Work -match '[^\x20-\x7e]' -or $Work.Length -gt 60) { $Work = 'C:\aseprite-build' } } $building = Join-Path $Work 'building.txt' if (-not $AsepriteVersion -and (Test-Path $building)) { $was = "$(Get-Content $building -Raw -ErrorAction SilentlyContinue)".Trim() if ($was -match '^\d+(\.\d+)+$') { $AsepriteVersion = $was } } if (-not $AsepriteVersion) { $AsepriteVersion = $Pinned } $InstallDir = Join-Path $env:LOCALAPPDATA 'Programs\Aseprite' function Say($m) { Write-Host "`n$m" -ForegroundColor Cyan } function Ask($q) { if ($env:ASEPRITE_YES) { return $true }; $a = Read-Host "$q [Y/n]"; return ($a -eq '' -or $a -match '^[Yy]') } function Fetch($url, $out, $quiet) { if ((Test-Path $out) -and (Get-Item $out).Length -gt 0) { return } if (Get-Command curl.exe -ErrorAction SilentlyContinue) { if ($quiet) { curl.exe -fsSL --retry 3 -o "$out.part" $url } else { curl.exe -fL --retry 3 --progress-bar -o "$out.part" $url } if ($LASTEXITCODE -ne 0) { throw "a download did not finish. Check your internet connection." } } else { Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile "$out.part" } Move-Item -Force "$out.part" $out } # Pipe native output through PowerShell for Start-Transcript. Native stderr can contain progress messages. function Run { $exe, $rest = $args # use positional args to pass flags such as -e verbatim $old = $ErrorActionPreference; $ErrorActionPreference = 'Continue' # empty stderr records stringify as RemoteException & $exe @rest 2>&1 | ForEach-Object { if ($_ -is [System.Management.Automation.ErrorRecord]) { Write-Host $_.Exception.Message } else { Write-Host "$_" } } $code = $LASTEXITCODE; $ErrorActionPreference = $old return $code } function Unzip($zip, $dest) { if (Test-Path (Join-Path $dest '.ok')) { return } if (Test-Path $dest) { Stop-Helper; Remove-Item -Recurse -Force $dest } New-Item -ItemType Directory -Force $dest | Out-Null $done = $false # tar.exe is faster for large source trees. if (Get-Command tar.exe -ErrorAction SilentlyContinue) { tar.exe -xf $zip -C $dest; $done = ($LASTEXITCODE -eq 0) } if (-not $done) { try { Expand-Archive -Force $zip $dest } catch { Remove-Item -Force $zip; throw "a download was damaged." } } Set-Content (Join-Path $dest '.ok') 'ok' } # 32-bit PowerShell reports x86 even on a 64-bit host. $arch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE } if ($arch -ne 'AMD64') { throw "this PC's processor is not supported (it needs a 64-bit Intel or AMD processor)." } $vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe' function Find-VS { if (Test-Path $vswhere) { & $vswhere -latest -products * -version '[17.0,)' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath } } $vs = Find-VS $msvc = Join-Path $Work 'msvc' $dl = Join-Path $Work 'msvc-downloads' # mspdbsrv can hold compiler files open after the build function Stop-Helper { Get-Process mspdbsrv -ErrorAction SilentlyContinue | Where-Object { $_.Path -and $_.Path.StartsWith($Work, [StringComparison]::OrdinalIgnoreCase) } | Stop-Process -Force -ErrorAction SilentlyContinue; Start-Sleep -Milliseconds 500 } function Read-Json($path) { $text = [IO.File]::ReadAllText($path) # the .NET reader avoids slow ConvertFrom-Json parsing on Windows PowerShell try { Add-Type -AssemblyName System.Web.Extensions $js = New-Object System.Web.Script.Serialization.JavaScriptSerializer $js.MaxJsonLength = [int]::MaxValue return $js.DeserializeObject($text) } catch { return ($text | ConvertFrom-Json) } } if (-not $vs) { # display the licence before downloading packages $tmp = [IO.Path]::GetTempFileName() try { Remove-Item -Force $tmp; Fetch 'https://aka.ms/vs/17/release/channel' $tmp $true; $chan = Read-Json $tmp } finally { Remove-Item -Force $tmp -ErrorAction SilentlyContinue } $bt = @($chan.channelItems | Where-Object { $_.id -eq 'Microsoft.VisualStudio.Product.BuildTools' })[0] $license = @($bt.localizedResources | Where-Object { $_.language -eq 'en-us' })[0].license if (-not $license) { throw "could not read Microsoft's list of compiler files. Check your internet connection." } } Say "Building Aseprite $AsepriteVersion for Windows" if ($vs) { Write-Host "This takes 10 to 30 minutes and needs about 2 GB free while it works." Write-Host "Once it is done, Aseprite itself is small. Keep this window open until it says Done." } else { Write-Host "This downloads Microsoft's C++ compiler (about 390 MB) and builds Aseprite with it. It takes 10 to 30 minutes" Write-Host "and needs about 3 GB free while it works. Afterwards only Aseprite is left: the compiler is deleted too." Write-Host "Microsoft's compiler comes with its own license: $license" Write-Host "Starting means you accept it. Keep this window open until it says Done." } if (-not (Ask 'Start?')) { Write-Host "Okay, nothing was changed."; return } New-Item -ItemType Directory -Force $Work | Out-Null Set-Content -Encoding ASCII $building $AsepriteVersion # unpacking the compiler can exceed 2 GB $need = if ($vs) { 2GB } else { 3GB } $d = (Get-Item $Work).PSDrive.Name $free = (Get-PSDrive $d -ErrorAction SilentlyContinue).Free if ($free -and $free -lt $need) { throw "this needs about $($need / 1GB) GB of free space on drive ${d}:. Free some space." } Say "Step 1 of 4: Getting the build tools" if (-not $vs -and (Get-Content (Join-Path $msvc '.ok') -ErrorAction SilentlyContinue) -ne 'ok2') { # ok2 marks toolchains that include oldnames.lib Write-Host "Downloading Microsoft's C++ compiler (the biggest download)..." if (Test-Path $msvc) { Stop-Helper; Remove-Item -Recurse -Force $msvc } New-Item -ItemType Directory -Force $msvc, $dl | Out-Null $man = Join-Path $dl 'vs.json' Remove-Item -Force $man -ErrorAction SilentlyContinue $item = @($chan.channelItems | Where-Object { $_.id -eq 'Microsoft.VisualStudio.Manifests.VisualStudio' })[0] Fetch $item.payloads[0].url $man $true $man = Read-Json $man $pk = @{} foreach ($p in $man.packages) { $k = [string]$p.id; if (-not $pk.ContainsKey($k)) { $pk[$k] = New-Object Collections.ArrayList }; [void]$pk[$k].Add($p) } function Pkg($id) { if ($pk.ContainsKey($id)) { @($pk[$id] | Where-Object { -not $_.language -or $_.language -eq 'en-US' })[0] } } function Part($pay) { $f = Join-Path $dl ([IO.Path]::GetFileName(($pay.fileName -replace '\\', '/'))) Fetch ($pay.url -replace ' ', '%20') $f $true if ((Get-FileHash $f -Algorithm SHA256).Hash -ne $pay.sha256) { Remove-Item -Force $f; throw "a download was damaged. Check your internet connection." } return $f } $pre = Pkg 'Microsoft.VC.Preview.Tools.HostX64.TargetX64' $preMinor = if ($pre) { (([string]$pre.version) -split '\.')[0..1] -join '.' } else { '' } $mv = $null; $sv = 0; $sdkId = $null foreach ($k in @($pk.Keys)) { if ($k -match '^microsoft\.vc\.(\d+\.\d+)\.(\d+\.\d+)\.tools\.hostx64\.targetx64\.base$') { $minor = $matches[1]; $v = $matches[1] + '.' + $matches[2] if ($minor -ne $preMinor -and (-not $mv -or [version]$v -gt [version]$mv)) { $mv = $v } } elseif ($k -match '^microsoft\.visualstudio\.component\.windows1[01]sdk\.(\d+)$') { if ([int]$matches[1] -gt $sv) { $sv = [int]$matches[1]; $sdkId = $k } } } if (-not $mv -or -not $sdkId) { throw "could not find the compiler in Microsoft's list of files." } $deps = (Pkg $sdkId).dependencies $depIds = if ($deps -is [Collections.IDictionary]) { @($deps.Keys) } else { @($deps.PSObject.Properties.Name) } $sdk = Pkg @($depIds | Where-Object { $_ -match '^Win1[01]SDK_' })[0] if (-not $sdk) { throw "could not find the Windows SDK in Microsoft's list of files." } Add-Type -AssemblyName System.IO.Compression.FileSystem $parts = 'CRT.Headers.base', 'CRT.x64.Desktop.base', 'CRT.x64.Store.base', 'Tools.HostX64.TargetX64.base', 'Tools.HostX64.TargetX64.Res.base', 'Premium.Tools.HostX64.TargetX64.base', 'PGO.Headers.base', 'PGO.x64.base' foreach ($n in $parts) { $p = Pkg "Microsoft.VC.$mv.$n" if (-not $p) { if ($n -match '^(Premium|PGO)') { continue }; throw "Microsoft's list of compiler files is missing a part ($n)." } foreach ($pay in @($p.payloads)) { $z = [IO.Compression.ZipFile]::OpenRead((Part $pay)) try { foreach ($e in $z.Entries) { if (-not $e.FullName.StartsWith('Contents/') -or -not $e.Name) { continue } $out = [IO.Path]::Combine($msvc, [Uri]::UnescapeDataString($e.FullName.Substring(9))) [void][IO.Directory]::CreateDirectory([IO.Path]::GetDirectoryName($out)) [IO.Compression.ZipFileExtensions]::ExtractToFile($e, $out, $true) } } finally { $z.Dispose() } } } # Windows SDK MSI payloads reference adjacent CAB files. $pays = @{} foreach ($x in @($sdk.payloads)) { $f = $x.fileName -replace '\\', '/'; if ($f -like 'Installers/*') { $pays[$f.Substring(11)] = $x } } $msis = @(); $cabs = @{} $names = @('Windows SDK for Windows Store Apps Tools', 'Windows SDK for Windows Store Apps Headers', 'Windows SDK for Windows Store Apps Headers OnecoreUap', 'Windows SDK for Windows Store Apps Libs', 'Universal CRT Headers Libraries and Sources', 'Windows SDK Desktop Libs x64') + @(foreach ($a in 'x64', 'x86', 'arm', 'arm64') { "Windows SDK Desktop Headers $a"; "Windows SDK OnecoreUap Headers $a" }) foreach ($n in $names) { $x = $pays["$n-x86_en-us.msi"] if (-not $x) { continue } $m = Part $x $msis += $m $text = [Text.Encoding]::GetEncoding(28591).GetString([IO.File]::ReadAllBytes($m)) foreach ($c in [regex]::Matches($text, '[0-9a-f]{32}\.cab')) { $cabs[$c.Value] = $true } } if ($msis.Count -lt 5 -or $cabs.Count -eq 0) { throw "could not find the Windows SDK in Microsoft's list of files." } foreach ($c in @($cabs.Keys)) { if ($pays[$c]) { [void](Part $pays[$c]) } } # administrative install extracts files locally $msiexec = Join-Path $env:SystemRoot 'System32\msiexec.exe' foreach ($m in $msis) { $p = Start-Process -Wait -PassThru -FilePath $msiexec -ArgumentList "/a `"$m`" /quiet /qn TARGETDIR=`"$msvc`"" if ($p.ExitCode -ne 0) { throw "Windows could not unpack part of Microsoft's compiler (code $($p.ExitCode))." } } Get-ChildItem $msvc -Filter *.msi -File | Remove-Item -Force # vctip.exe reports compiler usage $kits = Join-Path $msvc 'Windows Kits\10' $kv = (Get-ChildItem (Join-Path $kits 'bin') -Directory | Where-Object { $_.Name -like '10.*' } | Select-Object -First 1).Name Remove-Item -Recurse -Force -ErrorAction SilentlyContinue (Join-Path $kits 'Catalogs'), (Join-Path $kits 'DesignTime') foreach ($a in 'x86', 'arm', 'arm64') { Remove-Item -Recurse -Force -ErrorAction SilentlyContinue (Join-Path $kits "bin\$kv\$a"), (Join-Path $kits "Lib\$kv\ucrt\$a"), (Join-Path $kits "Lib\$kv\um\$a") } Remove-Item -Force -ErrorAction SilentlyContinue (Join-Path $msvc 'VC\Tools\MSVC\*\bin\Hostx64\x64\vctip.exe') foreach ($f in 'store', 'uwp', 'enclave', 'onecore') { Remove-Item -Recurse -Force -ErrorAction SilentlyContinue (Join-Path $msvc "VC\Tools\MSVC\*\lib\x64\$f") } Remove-Item -Recurse -Force $dl Set-Content (Join-Path $msvc '.ok') 'ok2' } if (-not $vs) { $vc = (Get-ChildItem (Join-Path $msvc 'VC\Tools\MSVC') -Directory | Sort-Object Name | Select-Object -Last 1).FullName $kits = Join-Path $msvc 'Windows Kits\10' $kv = (Get-ChildItem (Join-Path $kits 'bin') -Directory | Where-Object { $_.Name -like '10.*' } | Select-Object -First 1).Name $env:Path = "$vc\bin\Hostx64\x64;$kits\bin\$kv\x64;$kits\bin\$kv\x64\ucrt;" + $env:Path $env:INCLUDE = "$vc\include;$kits\Include\$kv\ucrt;$kits\Include\$kv\shared;$kits\Include\$kv\um;$kits\Include\$kv\winrt;$kits\Include\$kv\cppwinrt" $env:LIB = "$vc\lib\x64;$kits\Lib\$kv\ucrt\x64;$kits\Lib\$kv\um\x64" $miss = @(foreach ($t in 'cl.exe', 'link.exe', 'rc.exe', 'mt.exe') { if (-not (Get-Command $t -ErrorAction SilentlyContinue)) { $t } }) + @(foreach ($t in "$vc\lib\x64\oldnames.lib", "$vc\lib\x64\libcmt.lib", "$kits\Lib\$kv\ucrt\x64\libucrt.lib", "$kits\Lib\$kv\um\x64\kernel32.lib", "$kits\Include\$kv\um\windows.h") { if (-not (Test-Path $t)) { Split-Path $t -Leaf } }) if ($miss) { Write-Host ("Missing: " + ($miss -join ', ')) Remove-Item -Force -ErrorAction SilentlyContinue (Join-Path $msvc '.ok') throw "Microsoft's compiler did not unpack properly." } } else { # Use a command file for vcvars paths containing parentheses. # Preserve existing profile variables because cmd can corrupt accented usernames. $envCmd = Join-Path $Work 'vs-env.cmd' # separate vcvars diagnostics from environment assignments Set-Content -Encoding ASCII $envCmd "@call `"$(Join-Path $vs 'VC\Auxiliary\Build\vcvars64.bat')`" 2>&1`r`n@echo ===settings===`r`n@set" $said = @(); $inSet = $false $before = @{}; foreach ($n in 'PATH', 'INCLUDE', 'LIB', 'LIBPATH') { $before[$n] = [Environment]::GetEnvironmentVariable($n, 'Process') } # System32 can be missing from PATH & (Join-Path $env:SystemRoot 'System32\cmd.exe') /c call $envCmd | ForEach-Object { if ($_ -eq '===settings===') { $inSet = $true } elseif (-not $inSet) { if ($_ -match '\S' -and $_ -notmatch '^\*+$') { $said += $_ } } elseif ($_ -match '^([^=]+)=(.*)$') { # capture both groups before another -match overwrites $matches $n = $matches[1]; $v = $matches[2] if ($null -eq [Environment]::GetEnvironmentVariable($n, 'Process') -or @('PATH', 'INCLUDE', 'LIB', 'LIBPATH') -contains $n) { [Environment]::SetEnvironmentVariable($n, $v, 'Process') } } } if (-not (Get-Command cl.exe -ErrorAction SilentlyContinue)) { foreach ($n in $before.Keys) { [Environment]::SetEnvironmentVariable($n, $before[$n], 'Process') } $said | Select-Object -Last 8 | ForEach-Object { Write-Host " $_" } throw "Visual Studio's C++ compiler did not load. Its own messages are above." } } $tools = Join-Path $Work 'tools' if (-not (Get-Command cmake.exe -ErrorAction SilentlyContinue)) { Fetch "https://github.com/Kitware/CMake/releases/download/v$CMakeVersion/cmake-$CMakeVersion-windows-x86_64.zip" (Join-Path $Work 'cmake.zip') Unzip (Join-Path $Work 'cmake.zip') (Join-Path $tools 'cmake') $env:Path = (Join-Path $tools "cmake\cmake-$CMakeVersion-windows-x86_64\bin") + ';' + $env:Path } if (-not (Get-Command ninja.exe -ErrorAction SilentlyContinue)) { Fetch "https://github.com/ninja-build/ninja/releases/download/v$NinjaVersion/ninja-win.zip" (Join-Path $Work 'ninja.zip') Unzip (Join-Path $Work 'ninja.zip') (Join-Path $tools 'ninja') $env:Path = (Join-Path $tools 'ninja') + ';' + $env:Path } Say "Step 2 of 4: Downloading Aseprite" $src = Join-Path $Work "aseprite-$AsepriteVersion" Fetch "https://github.com/aseprite/aseprite/releases/download/v$AsepriteVersion/Aseprite-v$AsepriteVersion-Source.zip" "$src.zip" Unzip "$src.zip" $src $skiaTag = (Get-Content (Join-Path $src 'laf\misc\skia-tag.txt') -Raw).Trim() $skia = Join-Path $Work "skia-$skiaTag-x64" Fetch "https://github.com/aseprite/skia/releases/download/$skiaTag/Skia-Windows-Release-x64.zip" "$skia.zip" Unzip "$skia.zip" $skia Say "Step 3 of 4: Building (the long part, 10 to 30 minutes. Lots of text is normal)" $build = Join-Path $src 'build' $configured = Join-Path $build 'configured.ok' if (-not (Test-Path $configured)) { Remove-Item -Force (Join-Path $build 'CMakeCache.txt') -ErrorAction SilentlyContinue } Remove-Item -Force $configured -ErrorAction SilentlyContinue # Pin cl to avoid another compiler on PATH. PowerShell splits unquoted -D values containing a dot. $code = Run cmake -S $src -B $build -G Ninja --no-warn-unused-cli "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" "-DLAF_BACKEND=skia" ` "-DCMAKE_C_COMPILER=cl" "-DCMAKE_CXX_COMPILER=cl" ` "-DSKIA_DIR=$skia" "-DSKIA_LIBRARY_DIR=$skia\out\Release-x64" "-DSKIA_LIBRARY=$skia\out\Release-x64\skia.lib" if ($code -ne 0) { throw "the build could not be set up. Scroll up for the first error." } Set-Content -Encoding ASCII $configured 'ok' $code = Run cmake --build $build --target aseprite if ($code -ne 0) { throw "the build failed. Scroll up for the first error." } $exe = Join-Path $build 'bin\aseprite.exe' if (-not (Test-Path $exe)) { throw "the build finished without making aseprite.exe." } Say "Step 4 of 4: Installing" if (Get-Process aseprite -ErrorAction SilentlyContinue) { throw "Aseprite is open. Close it, then run the command again (it finishes much faster this time)." } $new = "$InstallDir.new"; $gone = "$InstallDir.old" if (Test-Path $new) { Remove-Item -Recurse -Force $new } New-Item -ItemType Directory -Force $new | Out-Null Copy-Item -Recurse -Force (Join-Path $build 'bin\*') $new -Exclude *.pdb, *.ilk, *.lib, *.exp, gen.exe if (-not (Test-Path (Join-Path $new 'aseprite.exe'))) { throw "Aseprite could not be copied into place." } if (Test-Path $gone) { Remove-Item -Recurse -Force $gone } if (Test-Path $InstallDir) { Move-Item -Force $InstallDir $gone } try { Move-Item -Force $new $InstallDir } catch { if ((Test-Path $gone) -and -not (Test-Path $InstallDir)) { Move-Item -Force $gone $InstallDir } throw } Remove-Item -Recurse -Force $gone -ErrorAction SilentlyContinue $shell = New-Object -ComObject WScript.Shell foreach ($l in @((Join-Path ([Environment]::GetFolderPath('Programs')) 'Aseprite.lnk'), (Join-Path ([Environment]::GetFolderPath('Desktop')) 'Aseprite.lnk'))) { $s = $shell.CreateShortcut($l) $s.TargetPath = Join-Path $InstallDir 'aseprite.exe' $s.WorkingDirectory = $InstallDir $s.Save() } # keep Skia for updates and retain partial builds for retry Say "Cleaning up the build files" Stop-Helper Remove-Item -Force $building -ErrorAction SilentlyContinue $old = @(Get-ChildItem $Work -Force | Where-Object { $_.Name -match '^(aseprite-|skia-|msvc|vs_BuildTools\.exe$|vs-env\.cmd$)' -and $_.FullName -ne "$skia.zip" }) # remove the marks first, so a half-deleted folder is unpacked afresh foreach ($o in $old) { if ($o.PSIsContainer) { Remove-Item -Force (Join-Path $o.FullName '.ok') -ErrorAction SilentlyContinue } } $old | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue Say "Done! Aseprite is in your Start menu and on your desktop." Write-Host "To update later, run the same command again." if ($vs -match 'BuildTools') { Write-Host "Microsoft's build tools are installed on this PC (about 5 GB). This no longer needs them: if nothing else does, uninstall Visual Studio Build Tools 2022 in Settings > Apps." } Start-Process (Join-Path $InstallDir 'aseprite.exe') } $log = Join-Path ([Environment]::GetFolderPath('Desktop')) 'Aseprite build log.txt' $logging = $false try { Start-Transcript -Path $log -Force | Out-Null; $logging = $true } catch {} $ok = $false $envWas = @{} foreach ($e in [Environment]::GetEnvironmentVariables('Process').GetEnumerator()) { $envWas[[string]$e.Key] = [string]$e.Value } try { Build-Aseprite; $ok = $true } catch { Write-Host "`nStopped: $($_.Exception.Message)" -ForegroundColor Red Write-Host "Run the same command again to continue where it stopped. Help: https://graal.codes/guides/get-aseprite-free" if ($logging) { Write-Host "Everything it printed is saved on your desktop in 'Aseprite build log.txt'." } } try { foreach ($k in @([Environment]::GetEnvironmentVariables('Process').Keys)) { if (-not $envWas.ContainsKey([string]$k)) { [Environment]::SetEnvironmentVariable([string]$k, $null, 'Process') } } foreach ($k in @($envWas.Keys)) { if ([Environment]::GetEnvironmentVariable($k, 'Process') -cne $envWas[$k]) { [Environment]::SetEnvironmentVariable($k, $envWas[$k], 'Process') } } } catch {} if ($logging) { try { Stop-Transcript | Out-Null } catch {} if ($ok) { Remove-Item -Force $log -ErrorAction SilentlyContinue } }