Category Archives: PowerShell

Powershell: Create new routes based on existing routes

bschelst/ June 8, 2019/ PowerShell/ 0 comments

It’s possible that you want to change routes on a system which point to a certain gateway, and replace them with a new gateway. The only thing this silly powershell is doing, is getting the list of routes, filter out the ‘old gateway’, replace that gateway, and put the deletes/add in a batch script which then can be executed when

Read More

PowerShell: using grep alike command

bschelst/ April 5, 2017/ PowerShell/ 0 comments

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: sls “Searchthisstring” “C:\myfile.log” -ca If you want to have the output without filename, line number: sls “Searchthisstring” “C:\myfile.log” -ca | Foreach-Object {$_.Line} If you want to ‘grep’ multiple words, you

Read More

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

bschelst/ January 5, 2017/ PowerShell/ 0 comments

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} {nx} {05/01/2017 19:52:58} {Visitor}      

Powershell: Find files larger than XXX

bschelst/ January 5, 2017/ PowerShell/ 0 comments

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 | Where-Object {$_.Length -gt 100MB}  

Powershell: Open TCP listener port

bschelst/ January 5, 2017/ PowerShell/ 0 comments

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 following commands: $Listener = [System.Net.Sockets.TcpListener]4444; $Listener.Start(); Where “4444” is the TCP port that you want to open.Once ready, you need to stop

Read More

Powershell: get TCP counters for IPv4

bschelst/ January 5, 2017/ PowerShell/ 0 comments

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 getting the counters for IPv4 TCP:   Get-Counter -Counter \TCPv4\*   This will give an output like this: Timestamp CounterSamples ——— ————–

Read More

Powershell: Set global dns searchlist

bschelst/ January 5, 2017/ PowerShell/ 0 comments

  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”)    

Powershell: Change binding order network interfaces

bschelst/ January 5, 2017/ PowerShell/ 0 comments

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 of the network cards.In order to do that, first get the interface index id.This can be found with the Get-NetIPInterface command in

Read More

PowerShell: Stop and/or Start a command at certain date/time

bschelst/ December 31, 2016/ PowerShell/ 0 comments

Hello, In addition to “PowerShell: Run command at certain date/time”, we got the request to include a start time also.In the script below, we are doing such thing. (write-host commands are in Dutch tho). In case the user specifies a valid start date/time, the script will start the program. (example program).If the user specifies a valid date/time, the script will kill that program. 

Read More