Category: Codes

How To Create a Windows Scheduled Task to Call a Program or Script

Example on How To Call a Program: Set Action = Start a Program Set Program/Script…

PowerShell: Delete Files Older Than 30 Days

Have you ever run into C:\ volumes reaching critical thresholds because certain applications or users…

PowerShell: How To Configure Static IP Address

$nicName='NIC1' $ipaddress='192.168.0.222' $cidrPrefix=24 $defaultGateway='192.168.0.1' $dnsServers=@('8.8.8.8','4.4.2.2') $disableIpv6=$true function setNic($nicName,$ipAddress,$cidrPrefix,$defaultGateway,$dnsServers,$disableIpv6=$true ){ $ifIndex=(get-netadapter|?{$_.Name -eq $nicName}).ifIndex New-NetIPAddress -InterfaceIndex $ifIndex…

PowerShell: Enable CredSSP on Windows

PowerShell: # Enabled WinRMEnable-PSRemoting -Force# Enable CredSSPEnable-WSManCredSSP -Role Server -Force Legacy Command Line: # Enable…

Windows UAC Error This App has been blocked for your protection mmc.exe taskschd.msc

Error Message: User Account ControlThis App has been blocked for your protection.A administrator has blocked…

PowerShell: Add Network Sites (VLAN) into a Virtual Machine Manager Logical Network

# addVmmNetworkSites.ps1 # version 0.01 # User Defined Variables $networkSites=@( @{ 'newNetworkSitename'="test 1" 'vlanId'=100 'vlanCidr'='192.168.1.0/24'…

PowerShell: Automatically Fix SQL Server by Killing Long Running Queries

# autofixSqlLongRunningQueries.ps1 # version 0.01 # This version is limited to SQL Server Localhost execution,…

PowerShell: Add RDS Server Role

Step 0: Searching for RDS Licensing Server # Get TS Licensing Servers $termLicenseServers=Get-ADGroupMember -Identity "Terminal…

PowerShell: Unlimit RDP Sessions

$tsRegHive='REGISTRY::HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server' Set-ItemProperty -Path $tsRegHive -Name fSingleSessionPerUser -value 0 Set-ItemProperty -Path $tsRegHive -Name fdenyTSConnections -value…

PowerShell: Install Windows Exporter

Simple Version $windowsExporterUrl='https://github.com/prometheus-community/windows_exporter/releases/download/v0.20.0/windows_exporter-0.20.0-amd64.msi' $stageFolder='C:\Temp\' # Download the file Import-Module BitsTransfer $fileName=[regex]::match($windowsExporterUrl,'[^/\\&\?]+\.\w{3,4}(?=([\?&].*$|$))') $msiFile=join-path $stageFolder $fileName if(!(test-path…

PowerShell: Check Whether an Application Is Installed Using Known Service Name

# Check whether product is installed $serviceName='windows_exporter' function checkUninstall($serviceName){ $cpuArchitecture32bitPointerSize=4 $path=if ([IntPtr]::Size -eq $cpuArchitecture32bitPointerSize) {…

PowerShell: Download and Apply Windows Patch KB

The following snippet assumes that a Windows machine has access to download Microsoft patches directly…

PowerShell: Downloading File Error ‘Internet Explorer engine is not available’

Error Message: PS C:\temp> wget http://download.windowsupdate.com/d/msdownload/update/software/secu/2022/01/windows10.0-kb5009546-x64_d3ab97e9f811d7bf19c268e5e6b5e00e92e110ed.msu wget : The response content cannot be parsed because…

PowerShell: Search File Contents Matching a Phrase or String

$searchDirectories='C:\users\Public\.jenkins\jobs' $searchDepth=1 $fileNameScope='*.xml' $searchString='kimconnect' # Select the files and perform the search in each file…

PowerShell: Grant Current User Full Access to File or Folder

# Grant Current User Full Access to Object $object='C:\temp' $acl=Get-Acl $object $currentUser=[System.Security.Principal.WindowsIdentity]::GetCurrent().Name $grantAccess=New-Object System.Security.AccessControl.FileSystemAccessRule("$currentUser","FullControl","Allow") $acl.AddAccessRule($grantAccess)…

PowerShell: Check Windows Computers for Specific KB’s

# Check for specific KBs $kbs='KB5010790','KB5010419' $computernames=@('WINDOWS001','WINDOWS002') $regexIP = [regex] "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" $names=foreach($computername in $computernames){ if($computername…

How To Prevent Windows From Automatically Rebooting After Updates

# Add New Registry Key $regHive='REGISTRY::HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' $keyname='NoAutoRebootWithLoggedOnUsers' $value=1 Set-ItemProperty -Path $regHive -Name $keyname -value $value…

PowerShell: Get IP’s From Computer Names

Resolve from Names to IPs: $names=@( 'TESTVM001', 'TESTVM002', 'TESTVM003' ) foreach($name in $names){ $ips =…

Virtual Machine Manager (VMM) Error ID: 1730

Symptom: $vmName='bad-guestvm' $vm = Get-SCVirtualMachine -Name $vmName Read-SCVirtualMachine -VM $vm Read-SCVirtualMachine : The selected action…

PowerShell: Windows Get-EventLog vs Get-WinEvent

Get-Eventlog is the legacy Windows log querying command. Its advanced filtering is limited. Whereas Get-WinEvent,…