Category: Codes

How to Enforce Keyboard Layout Consistency for Remote Desktop

# The following function will allow the RDP session to store the user keyboard language…

PowerShell: Set DNS Server IPs on Default Network Interface

$dns1=.{ Import-Module ActiveDirectory $fsmoRoles=Get-ADDomainController -Filter *|Select-Object Name, Domain, Forest, OperationMasterRoles|Where-Object {$_.OperationMasterRoles}|select Name,OperationMasterRoles $pdcServer=($fsmoRoles|?{'PDCEmulator' -in $_.OperationMasterRoles}).Name…

PowerShell: Start IIS Sites & App Pools

Before running the below script, it's necessary to mark certain IIS App pools and websites…

Start All Automatic Services on Windows

Current version: # startAllAutoServices.ps1 # version 0.0.2 # Description: # - This script to scan…

SQL Error Msg 3201, Level 16, State 2

Sample Error Message: Msg 3201, Level 16, State 2, Line 2Cannot open backup device '\\1.1.1.1\d$\backup\TEST_MSCRM.bak'.…

PowerShell: Convert Array to Hash and back to Array

# convert 2D Array to Hash Table while removing any duplicate keys function arrayToHash($arr){ $hash…

PowerShell: Set User Option Change Password At Next Logon

$ou="OU=Users,DC=corp,DC=hooli,DC=com" $usersInOu=Get-ADUser -Filter * -SearchBase $ou $usersInOu|Set-ADUser -CannotChangePassword:$false -ChangePasswordAtLogon:$false

Querying Internal DNS for Host Record for iDRAC IPs

Copy / Paste for quick results: $domain='hooli.com'$records=Get-DnsServerResourceRecord -ZoneName $domain -ComputerName $env:USERDNSDOMAIN$records|?{$_.HostName -like '*drac*' -and $_.RecordType…

IIS Error Code 0x80070021

Error Message: Detailed Error Information:Module IIS Web CoreNotification BeginRequestHandler Not yet determinedError Code 0x80070021Config Error…

PowerShell: Get Terminal Service (Remote Desktop Service) Licenses Report

# rdsLicenseReport.ps1 $knownRdsComputers=$null # Options: (a) 'SERVER1','SERVER100' (b) Get-Content Path\To\RDServers.txt function getTsLicenses{ param( $knownRdsComputers, $domain=$env:userdnsdomain…

PowerShell: Test URL for Reachability

function testUrl($url){ try{ $HTTP_Request = [System.Net.WebRequest]::Create($url) $HTTP_Response = $HTTP_Request.GetResponse() [int]$HTTP_Status = [int]$HTTP_Response.StatusCode If ($HTTP_Status -eq…

PowerShell: Rename Photo and Video Files by Adding Creation Dates

Have you ever downloaded a punch of images, MOV, and MP4 from iCloud to find…

Invoke T-SQL on Multiple Servers

$computersAndCredentials=@{ 'SQL01'=@{'intranet\sql01Admin'='PASSWORD'} 'SQL02'=@{'intranet\sql02Admin'='PASSWORD'} 'SQL03'=@{'intranet\sql03Admin'='PASSWORD'} 'SQL04'=@{'intranet\sql04Admin'='PASSWORD'} } $tSql=" --Update the Setting with a new value: USE…

PowerShell: Get Event Logs from a List of Computers

Windows event logs contain a wealth of information that would be useful for analytical purposes.…

PowerShell: Find Process ID (PID) Locking a Certain File

Here's a function to kill common processes (Antivirus executable excluded) locking a particular file. This…

Microsoft Dynamics Email Router Failed to Start

Symptoms Event Log: Item 1: highest correlating event ID 26234 #26234 - The Email Router…

How To Invoke Functions as Background Jobs

Invoke-Command, Start-Job, Multi-Tasking is what good coders should aspire toward. Here, we're looking at some…

PowerShell: Update a List of Multiple Windows Machines

Version 3: # updateWindowsList.ps1 # Version 0.0.3 # # Features: # - New feature over…

PowerShell: Output HashTable to CSV

function outputHashtableToCsv{ param( $hashTable, $csvFile='C:\updateResults.csv', $headers=@('computerName','minutesToUpdate') ) try{ write-host $($hashTable|out-string) if(test-path $csvFile){ rename-item $csvFile "$csvFile.bak"…

PowerShell: Combine Objects

By default, a PowerShell Custom Object cannot be added to another. This would be the…