Category: Codes

PowerShell: Find Windows RDS Roles and Their Licensing Servers

# Get TS Licensing Servers (Enterprise or AD Registered) $termLicenseServers=Get-ADGroupMember -Identity "Terminal Server License Servers"…

PowerShell: Install App Using MSI on Remote Computers Via WinRM

# installMSiRemoteComputers.ps1 # version 0.0.1 $computernames='REMOTEPC001','REMOTEPC002' $thisMsiFile='C:\Temp\something.msi' $appName='testapp' $desiredVersion='1.0' $maxWaitSeconds=120 function installMsiOnRemoteComputers($computernames,$msiFile,$appName,$desiredVersion,$maxWaitSeconds){ function installMsiOnRemoteComputer{ param(…

PowerShell: Move Guest VM to Different Cluster in Hyper-V

# Assumptions: # - Guest VM files are stored at a single location # -…

PowerShell: How To Install VMM Agent on Hyper-V Nodes

# Update these variables to match your system $appName='Microsoft System Center Virtual Machine Manager Agent…

PowerShell: How to Convert Multi-Line Texts Into an Array of Strings

Significance: we often run into situations where a list of items (such as usernames, computernames,…

PowerShell: Remove Virtual Machine Snapshots in VMM

Base Cmdlets: $vmmServer='SOMETHINGHERE' $vmName='VMNAMEHERE' $snapshots=Get-SCVMCheckpoint -vmmserver $vmmServer -vm $(get-scvirtualmachine $vmName) $snapshots|%{Remove-SCVMCheckpoint -VMCheckpoint $_} Automation: #…

PowerShell: Add Local Group Members Onto a Server List

Sometimes, the GUI method of accomplishing tasks is too arduous and error prone. Thus, these…

Virtual Machine Manager Error ID 23351 FirstBootDevice Invalid

When moving, importing, exporting Generation 2 template in VMM, the following error occurs when trying…

PowerShell: Quickly Start Windows Services on Remote Computers

$computernames=@( "COMPUTER1", "COMPUTER2" ) $serviceName='windows_exporter' get-service $serviceName -computername $computernames|start-Service get-service $serviceName -computername $computernames|select MachineName,Name,Status Sample…

PowerShell: Search Windows Event Logs

# searchWindowsEventsLog.ps1 $computername=$env:computername $logType='Security' $eventId=4732 $daysBack=365 $limit=9999 $messageLike="*Remote Desktop Users*" function searchWindowsEvents{ param( $computername=$env:computername $logType='Security'…

PowerShell: Increase CPU Count or Memory of VMs via Virtual Machine Manager

# IncreaseCpuandRamViaVMM.ps1 # User Input Variables $vmNames=@( 'TESTWINDOWS', 'TESTWINDOWS2' ) $vmmServer=$env:computername $setCpuCount=8 $setDynamicMemory=$false $dynamicMemoryMinimumGB='2GB' $dynamicMemoryMaximumGB='16GB'…

PowerShell: Virtual Machine Snapshots Report from VMM Servers

# vmSnapshotReport.ps1 # Requirements: # - Credentials to access VMM Servers with Administrator role #…

PowerShell: Set VM Dynamic Memory in Virtual Machine Manager

# setVmDynamicMemoryInVmm.ps1 # Optimize Dynamic RAM $minGb='16GB' $maxGb='32GB' $startupGb='2GB' $buffer=20 $memoryWeight=5000 $forcedRestart=$false $vmmServer='localhost' function getUnoptimizedMemoryVms{…

PowerShell: Set DNS Records on Remote Computers

# setDnsEntries.ps1 $computernames=@( "$env:computername" ) $dnsServers=@( "8.8.8.8", "4.4.2.2" ) $results=[hashtable]@{} foreach ($computername in $computernames){ $psSession=new-pssession…

PowerShell: How To Append to Windows Environmental Paths Permanently

Often, when we install applications such as Python, its bin directory may not automatically be…

PowerShell: Grant SMB Access

# grantSmbAccess.ps1 $computername='fileserver' $shareName='TEST' $account='domain\groupOrUsername' $accessType='read' # also change or full invoke-command -computername $computername -scriptblock{…

How To Use CredSSP to Move Virtual Machines In a Hyper-V Cluster

# Prep on Client $domain='intranet.kimconnect.com' Enable-WSManCredSSP -Role "Client" -DelegateComputer "*.$domain" # Prep on Server Enable-WSManCredSSP…

Installing DotNet 3.5 on Windows with Restricted Internet Access

# Set Windows Source files # Assuming that a Windows ISO / DVD Rom have…

Disable and Enable Trace Logging for Dynamics CRM

# Set common variables $serverTracingRegistry='Registry::HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\MSCRM' # Enable CRM Tracing Add-PSSnapin Microsoft.Crm.PowerShell $setting = Get-CrmSetting TraceSettings…

PowerShell: Find Locking PID of a File

$filePath="C:\Program Files\Google\Chrome\Application\chrome.exe" function findPidOfFile($filepath){ try{ if (!(Get-Command handle.exe -ErrorAction SilentlyContinue)) { if (!(Get-Command choco.exe -ErrorAction…