Skip to content

Instantly share code, notes, and snippets.

@numbnet
Last active May 2, 2021 05:08
Show Gist options
  • Save numbnet/42e9494f26b949acc6f74fbbffd64b67 to your computer and use it in GitHub Desktop.
Save numbnet/42e9494f26b949acc6f74fbbffd64b67 to your computer and use it in GitHub Desktop.
<#
##
## start as ADMIN
#>
##*********************** ≠≠≠≠ ***********************
## start as ADMIN
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$testadmin = $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
if ($testadmin -eq $false) {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
exit $LASTEXITCODE
}
<#
########################################################################
Install OpenSSH
#>
##*********************** ≠≠≠≠ ***********************
## var
$OpenKEY = "<Add pub KEY>"
if ((Get-WmiObject win32_operatingsystem | select osarchitecture).osarchitecture -like "64*")
{
$ArhOS = "win64"; Write "Install for Windows x64";
} else {
$ArhOS = "win32"; Write "Install for Windows x86";
}
##*********************** ≠≠≠≠ ***********************
## var
$WebLink = "https://github.com/PowerShell/Win32-OpenSSH/releases/download/v8.1.0.0p1-Beta/OpenSSH-$ArhOS.zip"
$OutLink = "$env:SYSTEMDRIVE\PS\OpenSSH\OpenSSH-$ArhOS.zip"
$InDir = "$env:ProgramFiles\OpenSSH"
##*********************** ≠≠≠≠ ***********************
##
New-Item -Path $env:SYSTEMDRIVE\ -Name 'PS\OpenSSH' -ItemType Directory;
Invoke-WebRequest -Uri $WebLink -OutFile $OutLink;
Expand-Archive -Path $OutLink -DestinationPath $InDir;
copy $env:ProgramFiles\OpenSSH\OpenSSH-$ArhOS\* $InDir;
##*********************** ≠≠≠≠ ***********************
## Install service
. $env:ProgramFiles\OpenSSH\install-sshd.ps1
##*********************** ≠≠≠≠ ***********************
## Set firewall permissions
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22;
##*********************** ≠≠≠≠ ***********************
## Set service startup END
Set-Service sshd -StartupType Automatic;
Start-Service sshd;
##*********************** ≠≠≠≠ ***********************
## Set Authentication to public key
((Get-Content -path $env:ProgramData\ssh\sshd_config -Raw) ` -replace '#PubkeyAuthentication yes','PubkeyAuthentication yes' ` -replace '#PasswordAuthentication yes','PasswordAuthentication yes' ` -replace 'Match Group administrators','#Match Group administrators' ` -replace 'AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys','#AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys') | Set-Content -Path $env:ProgramData\ssh\sshd_config;
##*********************** ≠≠≠≠ ***********************
## Restart after changes
Restart-Service sshd;
##*********************** ≠≠≠≠ ***********************
## force file creation
New-item -Path "$env:USERPROFILE" -Name .ssh -ItemType Directory -force; # New-Item -Path $env:USERPROFILE\ -Name '.ssh\authorized_keys' -ItemType file;
echo "$OpenKEY" | Out-File $env:USERPROFILE\.ssh\authorized_keys -Encoding ascii;
cat $env:USERPROFILE\.ssh\authorized_keys
##*********************** ≠≠≠≠ ***********************
## Gen SSH Key
# ssh-keygen -t ed25519 -C "$env:USERNAME" -f $env:USERPROFILE\.ssh\$env:COMPUTERNAME.$(Get-Random).$env:USERNAME.ed25519.key | Out-File $env:USERPROFILE\.ssh\file.log -Encoding ascii;
# cat $env:USERPROFILE\.ssh\*$env:COMPUTERNAME.*.$env:USERNAME.ed25519.key.pub | Out-File $env:USERPROFILE\.ssh\authorized_keys -Encoding ascii;
##*********************** ≠≠≠≠ ***********************
## Cleaning Dir
Remove-Item -Path "$env:ProgramFiles\OpenSSH\OpenSSH-$ArhOS" -Recurse;
Remove-Item -Path $OutLink -Recurse;
pause
echo 'OpenSSH for windows is installed'
exit
<#
######################## ≠≠≠≠ ########################
## uninstall OpenSSH
echo ' vvvv DELETE OpenSSH from windows? '
echo "*********************** ≠≠≠≠ ***********************"
pause
. $env:ProgramFiles\OpenSSH\uninstall-sshd.ps1 | echo "OpenSSH is Unninstalled ... "
Remove-Item -Path "$env:ProgramFiles\OpenSSH" -Recurse | echo "$env:ProgramFiles\OpenSSH Is Removed ... "
Remove-Item -Path "$env:ProgramData\ssh" -Recurse | echo "$env:ProgramData\ssh Is Removed ... "
Remove-Item -Path "$env:USERPROFILE\.ssh" -Recurse | echo "$env:USERPROFILE\.ssh Is Removed ... "
##*********************** ≠≠≠≠ ***********************
echo 'OpenSSH is DELETED from PC";
echo "*********************** ≠≠≠≠ ***********************"
echo 'Script is exit";
pause
exit
#>
#$WinGetVersion = "v-0.3.11102-preview"
#$WinGetStokname = "Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.appxbundle"
#$WinGetLink = "https://github.com/microsoft/winget-cli/releases/download/$WinGetVersion/$WinGetStokname"
$WinGetLink = "https://github.com/microsoft/winget-cli/releases/download/v-0.3.11102-preview/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.appxbundle"
$OutLink = "$env:SYSTEMDRIVE\PS\WinGet.appxbundle"
Invoke-WebRequest -Uri "$WinGetLink" -OutFile $OutLink
Add-AppxPackage $OutLink;
winget search 7z
winget show 7zip.7zip
winget install 7zip.7zip
winget install Microsoft.WindowsTerminal –silent
#winget install Microsoft.VisualStudioCode –silent
##================================================================
## HOME WORK
winget install "VLC media player" --silent
winget install --id=TeamViewer.TeamViewer -e ;
winget install --id=Zoom.Zoom -e ;
winget install --id=Toggl.TogglDesktop -e ;
#winget install --id=Microsoft.Teams -e ;winget install --id=Notion.Notion -e ;winget install --id=SlackTechnologies.Slack -e ; winget install --id=ShareX.ShareX -e ;winget install --id=Loom.Loom -e ; winget install --id=LogMeIn.LastPass -e ;winget install --id=Spotify.Spotify -e ;winget install --id=Discord.Discord -e ;winget install --id=Microsoft.Skype -e ;winget install --id=Microsoft.Edge -e ;winget install --id=Mozilla.Firefox -e ;winget install --id=Google.Chrome -e ;winget install --id=Microsoft.OneDrive -e ;winget install --id=Google.DriveFileStream -e
##================================================================
## Web Browsers
# winget install --id=Microsoft.Edge -e ; winget install --id=Mozilla.Firefox -e ; winget install --id=Google.Chrome -e ; winget install --id=BraveSoftware.BraveBrowser -e ; winget install --id=Opera.Opera -e ; winget install --id=VivaldiTechnologies.Vivaldi -e ; winget install --id=Mozilla.FirefoxDeveloperEdition -e ; winget install --id=Google.ChromeBeta -e ; winget install --id=Microsoft.EdgeBeta -e ; winget install --id=Opera.OperaGX -e
##================================================================
## MESSENGERS
winget install --id=Telegram.TelegramDesktop --silent ;
winget install --id=WhatsApp.WhatsApp --silent ;
winget install --id=Microsoft.Skype -e ;
# winget install --id=MehediHassan.Tweeten -e ; winget install --id=Caprine.Caprine -e ; winget install --id=Signal.Signal -e ;winget install --id=AmineMouafik.Ferdi -e ; winget install --id=Discord.Discord -e ;winget install --id=SlackTechnologies.Slack -e ;winget install --id=Gitlab.Gitter.IM -e ; winget install --id=LINE.LINE -e ; winget install --id=Tencent.WeChat -e
####################################
## DEVELOPMENT
winget install --id=Notepad++.Notepad++ -e ;
winget install --id=Microsoft.WindowsTerminal -e ;
winget install --id=GitHub.Atom -h ;
winget install --id=Microsoft.VisualStudio.Community -e ;
# winget install --id=Python.Python -e ; winget install --id=PenguinLabs.Cacher -e winget install --id=GitHub.GitHubDesktop -e ; winget install --id=GitHub.cli -e ; winget install --id=TimKosse.FilezillaClient -e ; winget install --id=PuTTY.PuTTY -e ;winget install --id=Microsoft.VisualStudio.Professional -e ; winget install --id=Microsoft.VisualStudio.Enterprise -e ; winget install --id=vim.vim -e ; winget install --id=lukehaas.RunJS -e ; winget install --id=Toinane.Colorpicker -e
<#
########################################################################
Rename this Computer
#>
$NEWCOMPUTERNAME = "";
echo "This PC Name - $env:COMPUTERNAME";
if ($env:ComputerName -in $NEWCOMPUTERNAME) {
echo "
This is Computer - $env:COMPUTERNAME
========================================
";
exit
} else {
echo "Rename this Computer?"; pause; Rename-Computer -NewName $NEWCOMPUTERNAME -Force;
echo "Restart Computer? "; pause; Restart-Computer -Force -Confirm;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment