Python script learning resource: https://learnxinyminutes.com/docs/powershell/

Listing active ports

Powershell scripts usually have the .ps1 file extension. Execution: . .\\script.ps1

$system_ports = Get-NetTCPConnection -State Listen
$text_port = Get-Content -Path C:\\Users\\Administrator\\Desktop\\ports.txt
foreach($port in $text_port){
    if($port -in $system_ports.LocalPort){
        echo $port
     }
}

On the first line, we want to get a list of all the ports on the system that are listening. We do this using the Get-NetTCPConnection cmdlet. We are then saving the output of this cmdlet into a variable $system_ports.

On the next line, we want to read a list of ports from the file. We do this using the Get-Content cmdlet. Again, we store this output in the variables. The simplest next step is iterate through all the ports in the file to see if the ports are listening. To iterate we use foreach(){ }.

Looking for "password" inside files

$path = "C:\\Users\\Administrator\\Desktop\\emails\\*"
$string_pattern = "password"
$command = Get-ChildItem -Path $path -Recurse | Select-String -Pattern $String_pattern
echo $command

Untitled

How many open ports did you find between 130 and 140 (inclusive)?

for($i=130; $i -le 140; $i++){
    Test-NetConnection localhost -Port $i
}