Skip to content

Instantly share code, notes, and snippets.

@jsturtevant
Last active February 4, 2022 23:47
Show Gist options
  • Save jsturtevant/d709412fca0d8b4aff35d4c7cddb7517 to your computer and use it in GitHub Desktop.
Save jsturtevant/d709412fca0d8b4aff35d4c7cddb7517 to your computer and use it in GitHub Desktop.
Windows debug
http://localhost:8001/api/v1/nodes/2618k8s000/proxy/stats/summary
https://github.com/kubernetes/kubernetes/blob/1f70708f6cc85985725c11cd69c4965c1f97b314/pkg/kubelet/server/server.go#L17
http://localhost:8001/api/v1/nodes/win-p-win000000/proxy/logs/kubelet/
https://kubernetes.io/docs/reference/kubectl/cheatsheet/
https://docs.microsoft.com/en-us/azure/virtual-machines/troubleshooting/serial-console-cmd-ps-commands
# get status and info
Get-MpComputerStatus
# add exlussion
Add-MpPreference -ExclusionPath "C:\Temp"
#list exlusions set
Get-MpPreference | select Exclusion*
# spike cpu using powershell https://waynes-world-it.blogspot.com/2009/05/generating-100-cpu-with-calc-or.html
$result = 1; foreach ($number in 1..2147483647) {$result = $result * $number};
stop-service kubelet -Force
stop-service docker
#replace docker/kubelet/etc
start-service docker
start-service kubelet
#Get path name of executable for a service name
Get-WmiObject win32_service | ?{$_.Name -like '*docker*'} | select Name, DisplayName, State, PathName
#tail of file
Get-content -tail 5 file;
# size of file with name
Get-ChildItem C:\ProgramData\Docker\containers\*.log -Recurse | Select-object name, length
#versions of EE docker
$versions = (curl.exe -L "https://go.microsoft.com/fwlink/?LinkID=825636&clcid=0x409" | ConvertFrom-Json).Versions | Get-Member -Type NoteProperty | Select-Object Name
#get size of drive
Get-PSDrive
#CPU and memory
Get-Counter '\Processor(_Total)\% Processor Time'
Get-Counter '\Memory\Available MBytes'
typeperf "\Processor(_Total)\% Processor Time"
# current process samples
# https://powershelladministrator.com/2015/12/03/get-current-cpu-usage-for-a-process/
Get-Counter "\Process(kubelet*)\% Processor Time" -SampleInterval 1 -MaxSamples 5
# top process using more than 10% (change value `$NumberOfLogicalProcessors*N` for precentage)
# https://stackoverflow.com/a/58294167
$NumberOfLogicalProcessors=(Get-WmiObject -class Win32_processor | Measure-Object -Sum NumberOfLogicalProcessors).Sum
(Get-Counter '\Process(*)\% Processor Time').Countersamples | Where cookedvalue -gt ($NumberOfLogicalProcessors*10) | Sort cookedvalue -Desc | ft -a instancename, @{Name='CPU %';Expr={[Math]::Round($_.CookedValue / $NumberOfLogicalProcessors)}}
# top five processes overall
Get-Process | Sort CPU -descending | Select -first 5 -Property ID,ProcessName,CPU | format-table -autosize
#https://dotnet-helpers.com/powershell/how-to-get-average-cpu-usage-of-a-computer-in-last-x-minute-with-powershell/
(GET-COUNTER -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 2 -MaxSamples 5 |select -ExpandProperty countersamples | select -ExpandProperty cookedvalue | Measure-Object -Average).average
#windows version
cmd /c ver
# use .net libraries
$path=[System.IO.Path]::Combine("\var","run", "secrets", "kubernetes.io", "serviceaccount")
[System.IO.File]::Exists("$path\token")
# get process args
WMIC path win32_process get Caption,Processid,Commandline | Select-String kubelet
# get start process info
(Get-Process dockerd).startinfo
# search directory and files for keyword
Select-String -path .\kubelet.* -Pattern somekey
#permissions https://stackoverflow.com/questions/47159963/how-to-remove-read-only-attribute-of-a-folder-by-powershell
$folder = Get-Item -Path path/to/folder
$folder.Attributes
#Get container processes (each container gets a session id)
ps | ? sessionid -eq 3
ps | ? sessionid -notin 0,1,2 | sort sessionid | ft id,name,sessionid
#list services and runas user
Get-WmiObject -Class Win32_Service | select displayname, startname, state
# ping service continually
for ($i=1; $i -le 20; $i++) { curl.exe --connect-timeout 1 http://10.98.39.203 }
Get-NetAdapter
Get-HnsNetwork | select name
get-vmswitch
#remove a network
get-hnsnetwork | ? Name -Like "External" | remove-hnsnetwork
#get endpoint policies
Get-HnsEndpoint | select name, IPAddress
Get-HnsEndpoint | ? IPAddress -like 192.168.196.8 | select -ExpandProperty policies
https://docs.microsoft.com/en-us/virtualization/windowscontainers/container-networking/architecture
#test connectivity
https://www.shellhacks.com/powershell-check-if-port-is-open-test-tcp-connection/
tnc www.shellhacks.com -p 443
curl.exe -LO https://download.sysinternals.com/files/SysinternalsSuite.zip
Expand-Archive SysinternalsSuite.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment