Skip to content

Instantly share code, notes, and snippets.

@nguyendown
Last active April 10, 2021 08:04
Show Gist options
  • Save nguyendown/8444892ab3dfef945d32d59270c9e765 to your computer and use it in GitHub Desktop.
Save nguyendown/8444892ab3dfef945d32d59270c9e765 to your computer and use it in GitHub Desktop.
windows pls
Import-Module -DisableNameChecking $PSScriptRoot\download.psm1
$Content = Invoke-RestMethod -Uri https://api.github.com/repos/yuk7/ArchWSL/releases/latest
$latestVersion = $Content.tag_name
$currentVersion = (Get-AppxPackage -Name yuk7.archwsl).Version
if ($currentVersion -eq $latestVersion) {
Write-Host 'Already have the latest version.'
Write-Host 'Press enter to reinstall.'
Read-Host
}
$certUrl = ($Content.assets.browser_download_url | Select-String -Pattern '.*\.cer$').ToString()
$appxUrl = ($Content.assets.browser_download_url | Select-String -Pattern '.*\.appx$').ToString()
Download-File $certUrl
Download-File $appxUrl
$certFilename = [System.IO.Path]::GetFileName($certUrl)
$appxFilename = [System.IO.Path]::GetFileName($appxUrl)
$certPath = $PSScriptRoot + "\" + $certFilename
$appxPath = $PSScriptRoot + "\" + $appxFilename
Import-Certificate -Filepath $certPath -CertStoreLocation cert:\LocalMachine\Root
Add-AppxPackage -Path $appxPath
if (Get-AppxPackage -Name yuk7.archwsl) {
'' | Arch
'pacman-key --init' | Arch -c "sed 's/\r//' | bash"
'pacman-key --populate' | Arch -c "sed 's/\r//' | bash"
}
Import-Module -DisableNameChecking $PSScriptRoot\download.psm1
choco install chromium 7zip mpv foobar2000 sublimetext3 sumatrapdf hashcheck everything -y
choco install microsoft-office-deployment -y #--params="'/Product ExcelRetail,PowerPointRetail,WordRetail'"
$picasa = (Download-File "https://web.archive.org/web/20160228082206if_/http://dl.google.com/picasa/picasa39-setup.exe" -Hash "482c1a547d8d3aa25ee446d30ea986de63ef8c8d68b8d1109dd3d9b714e73e08")
Invoke-Expression "$picasa /S"
cd /D "%~dp0"
powershell.exe -NoProfile -InputFormat None -ExecutionPolicy ByPass -File .\continue.ps1
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
powershell -File $PSScriptRoot\debloat.ps1
powershell -File $PSScriptRoot\choco.ps1
powershell -File $PSScriptRoot\archwsl.ps1
powershell -File $PSScriptRoot\sshd.ps1
Write-Host Completed.
Read-Host
$path = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search'
New-Item -Path $path -Force
Set-ItemProperty -Path $path -Name AllowCortana -Value 0
Set-ItemProperty -Path $path -Name AllowCortanaAboveLock -Value 0
Set-ItemProperty -Path $path -Name DisableWebSearch -Value 1
Set-ItemProperty -Path $path -Name ConnectedSearchUseWeb -Value 0
Set-ItemProperty -Path $path -Name ConnectedSearchUseWebOverMeteredConnections -Value 0
if (Test-Path $PSScriptRoot\Windows10Debloater\) {
Remove-Item $PSScriptRoot\Windows10Debloater\ -Recurse -Force
}
if (Test-Path $PSScriptRoot\Debloat-Windows-10\) {
Remove-Item $PSScriptRoot\Debloat-Windows-10\ -Recurse -Force
}
Set-Location $PSScriptRoot
git clone -q https://github.com/Sycnex/Windows10Debloater.git
git clone -q https://github.com/W4RH4WK/Debloat-Windows-10
powershell -File $PSScriptRoot\Windows10Debloater\Windows10SysPrepDebloater.ps1
$scripts = (Get-ChildItem "$PSScriptRoot" -Recurse | Where { $_.FullName -match "^.*scripts.*\.ps1$" }).FullName
foreach ($script in $scripts) {
powershell -File $script
}
function Download-File {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[String]
$Uri,
$Path = $PSScriptRoot,
$Hash
)
$filename = [System.IO.Path]::GetFileName($Uri)
$fullpath = $Path + "\" + $filename
while (-Not (Test-Path $fullpath)) {
Write-Host $fullpath 'not found. Downloading...'
(New-Object System.Net.WebClient).DownloadFile($Uri, $fullpath)
}
if (-Not $Hash) {
return $fullpath
}
if ($Hash -eq (Get-FileHash $fullpath).Hash) {
return $fullpath
}
Write-Host $fullpath
Write-Host Checksum does not match. Retrying...
rm $fullpath
return Download-File $Uri -Path $Path -Hash $Hash
}
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco upgrade chocolatey
choco install git -y
New-Item 'HKCU:\Software\Policies\Microsoft\Windows\Explorer' -Force
Set-ItemProperty -Path 'HKCU:\Software\Policies\Microsoft\Windows\Explorer' -Name DisableNotificationCenter -Value 1
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' -Name TaskbarSmallIcons -Value 1
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\System' -Name DontDisplayNetworkSelectionUI -Value 1
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' -Name ShutdownWithoutLogon -Value 0
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\TimeZoneInformation' -Name RealTimeIsUniversal -Value 1
New-Item 'HKLM:\SOFTWARE\Policies\Microsoft\Internet Explorer\Main' -Force
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Internet Explorer\Main' -Name DisableFirstRunCustomize -Value 1
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Keyboard Layout' -Name "Scancode Map" -PropertyType Binary -Value ([byte[]](0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x1d,0x00,0x3a,0x00,0x00,0x00,0x00,0x00))
# https://gist.github.com/Zenexer/ae98c2b80d60fffcc588
powershell -File $PSScriptRoot\cortana.ps1
powershell -File $PSScriptRoot\vcredist.ps1
# Get-WindowsOptionalFeature -Online
Enable-WindowsOptionalFeature -Online -FeatureName "NetFx3" -All
Enable-WindowsOptionalFeature -Online -FeatureName "Microsoft-Windows-Subsystem-Linux" -All
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name continue -Value "powershell -File ""$PSScriptRoot\continue.bat"""
powercfg /h off
Write-Host "Press enter to reboot."
Read-Host
Restart-Computer
cd /D "%~dp0"
powershell.exe -NoProfile -InputFormat None -ExecutionPolicy ByPass -File .\init.ps1
$name = (Get-WindowsCapability -Online | ? Name -like 'OpenSSH.Server*').Name
Add-WindowsCapability -Online -Name $name
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
Get-NetFirewallRule -Name *ssh*
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force
New-Item $profile -Type File -Force
'Set-PSReadlineOption -EditMode Emacs' > $profile
Set-PSReadlineOption -BellStyle None
https://github.com/PowerShell/PowerShell/releases
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
https://docs.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk
Import-Module -DisableNameChecking $PSScriptRoot\download.psm1
$versions = @(
"2005"
"2008"
"2010"
"2012"
"2013"
"2015"
"2017"
"2019"
)
$urls = @(
"https://download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x64.EXE"
"https://download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x86.EXE"
"https://download.microsoft.com/download/5/D/8/5D8C65CB-C849-4025-8E95-C3966CAFD8AE/vcredist_x64.exe"
"https://download.microsoft.com/download/5/D/8/5D8C65CB-C849-4025-8E95-C3966CAFD8AE/vcredist_x86.exe"
"https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x64.exe"
"https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x86.exe"
"https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe"
"https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x86.exe"
"https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe"
"https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe"
"https://download.microsoft.com/download/6/D/F/6DF3FF94-F7F9-4F0B-838C-A328D1A7D0EE/vc_redist.x64.exe"
"https://download.microsoft.com/download/6/D/F/6DF3FF94-F7F9-4F0B-838C-A328D1A7D0EE/vc_redist.x86.exe"
"https://download.visualstudio.microsoft.com/download/pr/36c5faaf-bd8b-433f-b3d7-2af73bae10a8/212f41f2ccffee6d6dc27f901b7d77a1/vc_redist.x64.exe"
"https://download.visualstudio.microsoft.com/download/pr/e9e1e87c-5bba-49fa-8bad-e00f0527f9bc/8e641901c2257dda7f0d3fd26541e07a/vc_redist.x86.exe"
"https://download.visualstudio.microsoft.com/download/pr/21614507-28c5-47e3-973f-85e7f66545a4/f3a2caa13afd59dd0e57ea374dbe8855/vc_redist.x64.exe"
"https://download.visualstudio.microsoft.com/download/pr/092cda8f-872f-47fd-b549-54bbb8a81877/ddc5ec3f90091ca690a67d0d697f1242/vc_redist.x86.exe"
)
$hashes = @(
"0551A61C85B718E1FA015B0C3E3F4C4EEA0637055536C00E7969286B4FA663E0"
"4EE4DA0FE62D5FA1B5E80C6E6D88A4A2F8B3B140C35DA51053D0D7B72A381D29"
"B811F2C047A3E828517C234BD4AA4883E1EC591D88FAD21289AE68A6915A6665"
"6B3E4C51C6C0E5F68C8A72B497445AF3DBF976394CBB62AA23569065C28DEEB6"
"CC7EC044218C72A9A15FCA2363BAED8FC51095EE3B2A7593476771F9EBA3D223"
"67313B3D1BC86E83091E8DE22981F14968F1A7FB12EB7AD467754C40CD94CC3D"
"681BE3E5BA9FD3DA02C09D7E565ADFA078640ED66A0D58583EFAD2C1E3CC4064"
"B924AD8062EAF4E70437C8BE50FA612162795FF0839479546CE907FFA8D6E386"
"E554425243E3E8CA1CD5FE550DB41E6FA58A007C74FAD400274B128452F38FB8"
"A22895E55B26202EAE166838EDBE2EA6AAD00D7EA600C11F8A31EDE5CBCE2048"
"D7257265DBC0635C96DD67DDF938A09ABE0866CB2D4FA05F8B758C8644E724E4"
"DAFB8B5F4B46BFAF7FAA1D0AD05211F5C9855F0005CD603F8B5037B6A708D6B6"
"B192E143D55257A0A2F76BE42E44FF8EE14014F3B1B196C6E59829B6B3EC453C"
"7355962B95D6A5441C304CD2B86BAF37BC206F63349F4A02289BCFB69EF142D3"
"14B07D8F4108A8B8B306AF3F6FE6EB78814DFADEBD500416FB24856AD668518E"
"261F8122CE3E3DA66FE4300E2A88325469251DA85B62FBDDB03EC49F97B62C14"
)
$paths = @()
foreach ($i in 0..$($versions.length - 1)) {
$path = $PSScriptRoot + "\vcredist\" + $($versions[$i])
if (-Not (Test-Path $path)) {
mkdir $path
}
$paths += Download-File $urls[$i*2] -Path $path -Hash $hashes[$i*2]
$paths += Download-File $urls[$i*2 + 1] -Path $path -Hash $hashes[$i*2 + 1]
}
foreach ($i in 0..($paths.length - 1)) {
$path = $paths[$i]
if ($i -lt 2) {
Write-Host "& '$path' /q | Out-Null"
Invoke-Expression "& '$path' /q | Out-Null"
} else {
Write-Host "& '$path' /q /norestart | Out-Null"
Invoke-Expression "& '$path' /q /norestart | Out-Null"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment