PowerShell

PowerShell: using grep alike command

In Powershell, you can also use a grep like you can do on Linux.In order to search for a string in a file, you can use the following command: If you want to have the output without filename, line number:…

Read More

Powershell: Check when a LOCAL user was last logged in.

Within Powershell you can also see when a LOCAL user was last logged in. This can be done with the following one-liner: $([ADSI]”WinNT://$env:COMPUTERNAME”).Children | where {$_.SchemaClassName -eq ‘user’} | ft name,lastlogin example output: name lastlogin —- ——— {localadmin} {28/09/2016 08:57:19}…

Read More

Powershell: Find files larger than XXX

With Powershell you can also find files which are larger than a certain size. This can be accomplished with the command below. In this example we are looking for files larger than 100MB, on the C drive. Get-ChildItem c:\ -Recurse…

Read More

Powershell: Open TCP listener port

If you want to test a firewall rule, while the application isn’t ready yet, you can start that port on the Windows server using Powershell. This way you can test the firewall functionality. Those actions can be done with the…

Read More

Powershell: get TCP counters for IPv4

Performance issues. Everybody had them once, and more 🙂 If you are using Windows 2012+ and Powershell, you can use the Get-Counter command in order to provide you more information regarding the TCP connections. In the example below, we are…

Read More

Powershell: Set global dns searchlist

If you want to configure the DNS suffix search list on Windows 2012+, you can use the set-DnsclientGlobalSetting command, as shown in the example below. This will set the DNS search list to “domain.local”: set-DnsClientGlobalSetting -SuffixSearchList  @(“domain.local”)

Read More

Powershell: Change binding order network interfaces

Sometimes there are some applications which take the ‘first network card’ in order to send/receive traffic. If you have multiple network cards, this can be problematic of course. In case you want to resolve that, you can change the order…

Read More

PowerShell: Stop command at certain date/time

Sometimes it can be handy to automatically stop a process at a certain time. I did this using the following powershell script. The script will first ask at what time it needs to be stopped. You can specify seconds if…

Read More