Skip to content

Instantly share code, notes, and snippets.

@nordineb
Last active December 14, 2023 00:05
Show Gist options
  • Select an option

  • Save nordineb/2ecd483d49d7d5c29657ff076926b07d to your computer and use it in GitHub Desktop.

Select an option

Save nordineb/2ecd483d49d7d5c29657ff076926b07d to your computer and use it in GitHub Desktop.
Windows Server Core Survival Guide

Set the keyboard layout

CHCP 65001
Import-Module International
powercfg -h off
powershell Set-WinUserLanguageList -LanguageList Nb-no -Force
Set-Culture nb-NO
&tzutil.exe /s "Romance Standard Time"

Install a better font

chcp 65001

cd d:\
d:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri https://github.com/be5invis/Iosevka/releases/download/v1.14.1/01-iosevka-1.14.1.zip -UseBasicParsing -OutFile font.zip
Expand-Archive font.zip -DestinationPath font -Force
$dirFiles = ".\font\ttf"
$srcFontFiles = Get-ChildItem "$($dirFiles)"
$srcFontFiles
$Fonts = (New-Object -ComObject Shell.Application).Namespace(0x14)
ForEach($srcFontFile in $srcFontFiles) 
{
  $srcFontFileName = $srcFontFile.name
  $srcFontFileFullPath = $srcFontFile.fullname
  $fonts.CopyHere($srcFontFileFullPath, 16) 
}


reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "iosevka-medium (TrueType)" /t REG_SZ /d "iosevka-medium.ttf" /f

cd 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont'
Set-ItemProperty -Path . -Name 000 -Value 'Iosevka Medium'
New-PSDrive HKU Registry HKEY_USERS
cd HKU:
cd (New-Object System.Security.Principal.NTAccount($env:USERNAME)).Translate([System.Security.Principal.SecurityIdentifier]).Value
Set-ItemProperty -Path 'Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe' -Name FaceName -Value 'Iosevka Medium'
Set-ItemProperty -Path 'Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe' -Name FontSize -Value 1572864
Set-ItemProperty -Path 'Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe' -Name FontWeight -Value 500

Set-ItemProperty -Path 'Console\%SystemRoot%_system32_cmd.exe' -Name FaceName -Value 'Iosevka Medium'
Set-ItemProperty -Path 'Console\%SystemRoot%_system32_cmd.exe' -Name FontSize -Value 1572864
Set-ItemProperty -Path 'Console\%SystemRoot%_system32_cmd.exe' -Name FontWeight -Value 500

Set-ItemProperty -Path 'Console\%SystemRoot%_SysWOW64_WindowsPowerShell_v1.0_powershell.exe' -Name FaceName -Value 'Iosevka Medium'
Set-ItemProperty -Path 'Console\%SystemRoot%_SysWOW64_WindowsPowerShell_v1.0_powershell.exe' -Name FontSize -Value 1572864
Set-ItemProperty -Path 'Console\%SystemRoot%_SysWOW64_WindowsPowerShell_v1.0_powershell.exe' -Name FontWeight -Value 500

cd c:\
Remove-PSDrive HKU

Powershell Remote

Setup on the server

Enable-PSRemoting -SkipNetworkProfileCheck -Force
Set-NetFirewallRule –Name "WINRM-HTTP-In-TCP-PUBLIC" –RemoteAddress 172.0.0.0/8

Setup on the client (Elevated powershell)

Start-Service WinRM
Get-Service WinRM
Set-Item WSMan:\localhost\Client\TrustedHosts -value 172.* -Force
Get-Item WSMan:\localhost\Client\TrustedHosts
sc.exe config WinRM start= "delayed-auto"
sc.exe start WinRM

usage

Interactive session

 Enter-PSSession -ComputerName 172.28.42.15 -Credential $null

Copy file/folder via powershell remoting

$target = New-PSSession -ComputerName 172.28.42.12 -Credential $null
Copy-Item -ToSession $Target -Path D:\tcping64.exe -Destination d:\ -Recurse

Task Manager

CTRL+ALT+END

Install utilities

using CMD.EXE

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
choco upgrade chocolatey
choco install mc
choco upgrade mc

Event log

Get-EventLog -List
Clear-Eventlog "Application" 
Get-EventLog -LogName Application -Newest 1 -EntryType Warning | select -ExpandProperty message

Or enable Remote Event Log Management

Set-NetFirewallRule -DisplayGroup 'Remote Event Log Management' -Enabled True -PassThru |
select DisplayName, Enabled

Failed Request Tracing (FREB)

C:\Windows\System32\inetsrv\appcmd.exe configure trace "Default Web Site/" /enable /path:*.aspx /timeTaken:00:10:00
C:\Windows\System32\inetsrv\appcmd.exe set config "Default Web Site" -section:system.webServer/tracing/traceFailedRequests /[path='*.aspx'].failureDefinitions.traceAllAfterTimeout:"True"
C:\Windows\System32\inetsrv\appcmd.exe list site
C:\Windows\System32\inetsrv\appcmd.exe set config -section:system.applicationHost/sites "/[name='xxx'].traceFailedRequestsLogging.enabled:True" /commit:apphost
C:\Windows\System32\inetsrv\appcmd.exe set config -section:system.applicationHost/sites "/[name='xxx'].traceFailedRequestsLogging.maxLogFiles:10" /commit:apphost
C:\Windows\System32\inetsrv\appcmd.exe set config -section:system.applicationHost/sites "/[name='xxx'].traceFailedRequestsLogging.directory:%SystemDrive%\inetpub\logs\FailedReqLogFiles" /commit:apphost
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri https://github.com/be5invis/Iosevka/releases/download/v1.14.1/01-iosevka-1.14.1.zip -UseBasicParsing -OutFile font.zip
Expand-Archive font.zip -DestinationPath font
$dirFiles = ".\font\ttf"
$srcFontFiles = Get-ChildItem "$($dirFiles)"
$srcFontFiles
$Fonts = (New-Object -ComObject Shell.Application).Namespace(0x14)
ForEach($srcFontFile in $srcFontFiles) 
{
  $srcFontFileName = $srcFontFile.name
  $srcFontFileFullPath = $srcFontFile.fullname
  $fonts.CopyHere($srcFontFileFullPath, 16) 
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Invoke-WebRequest -Uri https://github.com/git-for-windows/git/releases/download/v2.17.0.windows.1/Git-2.17.0-64-bit.exe -UseBasicParsing 
-OutFile git-install.exe
Start-Process -FilePath "git-install.exe" -ArgumentList -Wait -WorkingDirectory "d:\"

Invoke-WebRequest -Uri https://download.sysinternals.com/files/ProcessExplorer.zip -UseBasicParsing -OutFile processexplorer.zip
Expand-Archive processexplorer.zip -DestinationPath processexplorer

Invoke-WebRequest -Uri https://download.sublimetext.com/Sublime%20Text%20Build%203143%20x64.zip -UseBasicParsing -OutFile sublime.zip
Expand-Archive sublime.zip -DestinationPath sublime

Utils

npm install -g tldr
https://api.github.com/repos/getinsomnia/insomnia/releases/latest
https://docs.microsoft.com/en-us/sql/sql-operations-studio/download?view=sql-server-2017
https://www.jam-software.com/treesize_free/
https://www.codesector.com/teracopy
pip install mssql-cli

Enabling File Sharing to share c$

netsh advfirewall firewall set rule group=”File and Printer Sharing” new enable=Yes

install pfx

Import-PfxCertificate -CertStoreLocation Cert:\LocalMachine\My -FilePath C:\mypfx.pfx

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