Category: Codes

PowerShell: Automatically Log Off Idling Remote Desktop Sessions

Add this script to your task scheduler or Jenkins job to automatically log off Idling…

PowerShell: Get LastLogon Information of Computer Objects

$computernames=@( 'COMPUTER1', 'COMPUTER2' ) $computerLastLogon=foreach($computerName in $computernames){ get-adcomputer $computerName -Properties LastLogon|select Name,@{Name='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}} } $computerLastLogon|sort -Property…

PowerShell: How to Reset Windows Update Service

# resetWindowsUpdateService # This is a legacy method of reseting Windows Update # Since most…

PowerShell: How To Stop and Start Palo Alto Cortex XDR Traps

$trapsAdminPassword='PASSWORDHERE', $trapsBin='C:\Program Files\Palo Alto Networks\Traps' function stopXdr{ param( $trapsAdminPassword, $trapsBin='C:\Program Files\Palo Alto Networks\Traps' ) echo…

PowerShell: Maintaining Processes on Remote Servers

# maintainProcess.ps1 # version 0.0.1 $computernames=@( 'server1', 'server2' ) $processName='cmd' $processPath='C:\WINDOWS\system32\cmd.exe' $minutesToDefineCrashed=1 # this marker…

PowerShell: Find Duplicate Mac Addresses of Guest VMs in Virtual Machine Manager

Here's a quick snippet to check whether you have any duplicate mac addresses on existing…

PowerShell: Running Commands on Remote Computers

# runCommandsOnRemoteComputers.ps1 # User defined variables $computernames=@( 'SERVER001', 'SERVER002' ) $expectedExecutable='racadm.exe' $expectedInstallPath='C:\program files\Dell\SysMgt\iDRACTools\racadm' # Execution…

PowerShell: Installing a Program from Its Zip Archive

# installProgramFromExeZipArchive.ps1 # Automated installation of the racadm program $computerlist=@' HyperV01 HyperV02 '@ $fileURL="https://dl.dell.com/FOLDER08543783M/1/DellEMC-iDRACTools-Web-WINX64-10.3.0.0-4945.exe" $expectedExecutable='racadm.exe'…

How To Remove A Program on Windows Using PowerShell

# removeAppwizProgram.ps1 # Version 0.02 $computernames=@( 'SERVER0001', 'SERVER0002' ) $appName='Dell EMC OpenManage Systems Management Software…

How To Use Command Line to Configure iDrac Settings

Step 1: Install RacADM $computerlist=@' SERVER1 SERVER2 '@ $computernames=@($computerlist -split "`n")|%{$_.Trim()} $fileURL="https://dl.dell.com/FOLDER08543783M/1/DellEMC-iDRACTools-Web-WINX64-10.3.0.0-4945.exe" $expectedExecutable='racadm.exe' $expectedInstallPath='C:\Program Files\Dell\SysMgt\iDRACTools\racadm'…

PowerShell: Gather Information About Windows Shutdown Reasons

Copy and Paste this to See Result(s): $computername=$env:computername $limitEventsCount=40000 $daysSearchLimit=30 function getWindowsShutdownReason{ param( $computername=$env:computername, $limitEventsCount=10000,…

PowerShell: Converting Time Stamp from Int64 to DateTime and Vice Versa

Here are some quick conversion methods between time values represented by Integer and DateTime data…

Clean Windows C Volume

Have you ever ran into a sluggish performance on a Windows machine that is being…

PowerShell: Change Google Chrome Cache Directory

Lately, I've been running a buck load of chrome tabs that utilize all available I/O…

PowerShell: Assign Guest Virtual Machine to a Cloud in VMM

# assignVmsToCloud.ps1 # version 0.02 # The following function assigns a guest VM into a…

The Process of Adding a New Hyper-V Server Into a Cluster and the Associated Virtual Machine Manager (VMM)

These are the steps: Install WindowsWindows 2019 Data Center Edition is the standard as of…

PowerShell: Check a List of Windows Computers for Online & Offline Statuses

# checkOnlineComputers.ps1 # Set a list of computers in a text file $computerListFile='C:\Temp\computerlist.txt' # Read…

PowerShell: Add Local User as an Administrator on All Servers in Domain

# addLocalAccountOnAllServers.ps1 # Feature: using only legacy commands for maximum compatibility # Set variables $newUsername='backupAdmin'…

How To Modify a Windows Service

Here's the freebie code: # Version 0.02 $serviceName='Windows_Exporter' $newExePath=$false $newSwitches=" --log.format logger:eventlog?name=$serviceName --collectors.enabled os,cpu,cs,logical_disk,net,tcp,service,textfile" function…

How To Modify Collectors of Windows Exporter

Update: here's a generalized version of this function that can be applied to other services…