⚡ PowerShell
(17 posts)
PowerShell scripts and techniques for Windows and Active Directory administration, automation, and reporting.
📅 2023-11-06
✍️ Bart Schelstraete
The PowerShell script below logs off a disconnected session if the session has been idle for XX minutes, and it also excludes specific users. Additionally, the script writes a log file that includes…
Read more →
📅 2023-10-26
✍️ Bart Schelstraete
You can use the script below to download a file from a certain location to a temporary file, do a small check, and then copy it to a location. It also sends an email with some feedback. # Define…
Read more →
📅 2023-09-20
✍️ Bart Schelstraete
Below is example code which you can use to add users from a local CSV file (with their UPN) to an Active Directory group. # Start transcript Start-Transcript -Path C:\Temp\Add-ADUsers.log -Append #…
Read more →
📅 2023-08-21
✍️ Bart Schelstraete
Below is a high-level approach on how you might achieve this using PowerShell and the Azure CLI: Install Azure PowerShell: If you haven't already, install the Azure PowerShell module on your machine.…
Read more →
📅 2023-08-21
✍️ Bart Schelstraete
Use the PowerShell command below to get the list of processes on a remote Windows computer, sorted by CPU usage. $remoteComputerName = "rdwevw25" $session = New-PSSession -ComputerName…
Read more →
📅 2023-02-15
✍️ Bart Schelstraete
With the PowerShell script below, you can check TLS settings on Windows Server. Function Get-RegValue { [CmdletBinding()] Param ( # Registry Path [Parameter(Mandatory = $true, Position = 0)] [string]…
Read more →
📅 2019-06-08
✍️ Bart Schelstraete
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 script does is get the list of…
Read more →
📅 2017-04-05
✍️ Bart Schelstraete
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…
Read more →
📅 2017-01-13
✍️ Bart Schelstraete
List running processes and sort by CPU Get-Process | Sort-Object -Property cpu -Descending
Read more →
📅 2017-01-05
✍️ Bart Schelstraete
Within PowerShell you can also see when a LOCAL user last logged in. This can be done with the following one-liner: $([ADSI]"WinNT://$env:COMPUTERNAME").Children | where {$_.SchemaClassName -eq…
Read more →