Category: Codes

PowerShell: Get Spectre Meltdown Patching Versions of Hyper-V Hosts

function getHyperVHostsInForest{ function includeRSAT{ $ErrorActionPreference='stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #$rsatWindows7x32='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x86-RefreshPkg.msu' $rsatWindows7x64='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x64-RefreshPkg.msu' $rsatWindows81='https://download.microsoft.com/download/1/8/E/18EA4843-C596-4542-9236-DE46F780806E/Windows8.1-KB2693643-x64.msu' $rsat1709 = "https://download.microsoft.com/download/1/D/8/1D8B5022-5477-4B9A-8104-6A71FF9D98AB/WindowsTH-RSAT_WS_1709-x64.msu" $rsat1803…

Hyper-V Set CompatibilityForMigrationEnabled

$vmName='TESTVM' function enableCpuCompatibility($vmName){ $compatibilityForMigration=(Get-VMProcessor $vmName).CompatibilityForMigrationEnabled if(!$compatibilityForMigration){ $vmIsRunning=(get-vm $vmname).State -eq 'Running' if($vmIsRunning){stop-vm $vmName} Set-VMProcessor$vmName -CompatibilityForMigrationEnabled 1…

PowerShell: Set Virtual Machine Default Paths on Hyper-V Host of a Cluster

$newVirtualMachinePath='D:\VirtualMachines' $newVirtualHardDiskPath='D:\VirtualMachines' function getHyperVHostsInForest{ function includeRSAT{ $ErrorActionPreference='stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #$rsatWindows7x32='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x86-RefreshPkg.msu' $rsatWindows7x64='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x64-RefreshPkg.msu' $rsatWindows81='https://download.microsoft.com/download/1/8/E/18EA4843-C596-4542-9236-DE46F780806E/Windows8.1-KB2693643-x64.msu' $rsat1709 =…

PowerShell: Restore SQL Database from Full and/or Differential Backups

$databaseName='BALOO_MSCRM' $newDatabaseName='BALOO_MSCRM' $dbData='mscrm' # set this value to $null for autogen defaults $dbLog='mscrm_log' # set…

Microsoft SQL Cloning Database to a Different DB Name

# User defined variables $sourceSqlServer='DEV-SQL01' $sourceDatabaseName='TEST_MSCRM' $sourceSaCredential=$(get-credential) $destinationSqlServer='DEV-SQL01' $destinationDatabaseName='Test_MSCRM' $destinationSaCredential=$(get-credential) function copyDatabase{ param( $sourceSqlServer, $sourceDatabaseName,…

Windows 10 Missing Icons Problem

This sometimes happen when a certain app takes over icons cache in Windows, such as…

Virtual Machine Queue: Assigning Processors to Network Interfaces

Microsoft Hyper-V Virtual Machine Queuing is useful to maximize high-bandwidth network cards. However, configuring this…

PowerShell: Process Watcher – Restart Stopped Services

# processWatcher.ps1 # User Input $computername=$env:computername $serviceName='remoteregistry' $desiredStatus='Running' $action={ param($serviceName) $erroractionpreference='stop' try{ start-service $serviceName return…

Automating Scheduled Task Creation on Remote Computers

# createTaskScheduler.ps1 # What this script does: # 1. Ask user for valid Domain Admin…

Quick Script to Mount Remote UNC Paths as Local Drive Letters

Simple Mount: # Mapping a drive $username='domain\testAdmin' $password='PASSWORD' $remotePath='\\UNCSERVER\SHAREPATH\Backup' $unavailableDriveLetters=(Get-Volume).DriveLetter|sort $availableDriveLetters=.{(65..90|%{[char]$_})|?{$_ -notin $unavailableDriveLetters}} [char]$firstAvailableDriveLetter=$availableDriveLetters[0] $command="net…

PowerShell: Process Watcher

# processWatcher.ps1 # User Input $serviceName='MSCRMAsyncService$maintenance' # Semi-autogen variables $desiredStatus='Running' $environment=($env:computername).substring(0,$env:computername.IndexOf('-')) $reportServer="$environment-SQL01" function checkService($computername=$env:computername,$serviceName,$status='Running'){ #…

Resolving CRM Error Upon Login

Symptom: Error Message when trying to login to CRM [caption id="attachment_7481" align="alignnone" width="237"] INVALID ACTION[/caption]…

PowerShell: Get OU of a User & Get All Users In an OU

function getUserOu($username){ if(!(get-module activedirectory -ea SilentlyContinue)){ $osType=switch ((Get-CimInstance -ClassName Win32_OperatingSystem).ProductType){ 1 {'client'} 2 {'domaincontroller'} 3…

PowerShell: Test Domain Username & Password Credential

Version 2: function testCredential($username,$password){ # Get current domain using logged-on user's credentials $isDomainJoined=$env:USERDOMAIN -ne $env:COMPUTERNAME…

How to Add Domain Admins to SQL Server

Step 1: Right-click Start > Search > type in 'ssms.exe' > right-click Microsoft SQL Server…

PowerShell: Windows 10 Cleanup

Update: there's a new script to cleanup windows here. function cleanWindows{ write-host 'Disabling Windows Media…

PowerShell: Check Registry Path, Key, and Dword Value

$path='HKLM:\Software\Intel' $keyName='GMM' $dwordName='DedicatedSegmentSize' $dwordValue=512 Function CheckRegistryKey { param( [Parameter(Position = 0, Mandatory = $true)][String]$path, [Parameter(Position…

Linux: Enable PowerShell Remoting WinRM Client on Ubuntu 20.04

This note is a work-in-progress as the NTLM authentication support module by Microsoft for Ubuntu…

PowerShell: Purge, Destroy, or Empty a Directory!

# WARNING: THIS IS A VERY DESTRUCTIVE FUNCTION. IF EXECUTED AT THE WRONG DIRECTORY WHERE…

Tasks to Perform After Windows 10 Upgrade

Target for Windows upgrade cleanup: C:\$Windows.~BT\* C:\$Windows.~LS\* C:\$Windows.~WS\* C:\ESD\Download\* C:\ESD\Windows\* C:\$WINDOWS.~Q\* C:\$INPLACE.~TR\* C:\Windows.old\* C:\Windows\Panther Please…