Showing posts with label powershell. Show all posts
Showing posts with label powershell. Show all posts

17 April 2026

windows equivalents for popular unix commands

Some Windows cmd equivalents for common Unix commands and settings for my onw reference

unix cmd
powershell
echo $variable echo %variable% $variable
$env:variable //environment variable
~ %USERPROFILE% $env:USERPROFILE
variable=value %variable%=value $variable=value
cp source target copy source target  
cp -r source target 
xcopy source target /e/h
find -name '*.txt
dir /s *.txt
grep text
findstr text
ls -a dir /a
rm file del file
rm -rf directory rmdir /s /q directory
which command
where command             (gcm command).Path

14 September 2025

Windows powershell Get-Process: get parentprocess ID / name, get process using port...

Powershell command to get parent processes of all processes with a given name (e. g. javaw.exe):

Get-CimInstance Win32_Process -Filter "Name = 'javaw.exe'" | select ParentProcessId

Or in a script. This one takes the process name as a parameter and also shows the , this time with the parent process name: 

$targetProcessName = $args[0]

$targetProcessName = $args[0]
$targetProcesses = Get-CimInstance -ClassName Win32_Process -Filter "Name = '$targetProcessName'"

foreach ($process in $targetProcesses) {
    $parentProcessId = $process.ParentProcessId
    $parentProcess = Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = $parentProcessId"
    Write-Output "Process: $($process.processId) $($process.Name), Parent Process: $($ParentProcessId)    $($parentProcess.Name)"
}

Powershell command to get ID of process occupying a port (e.g. 8080)

 Get-Process -Id (Get-NetTCPConnection -LocalPort 8080).OwningProcess

 Once you have the id you can shoot it using 

taskkill /PID <processid> /F