Month: June 2020

A Broken PS-Session Issue

Symptoms: PS C:\Windows\system32> get-pssession Id Name ComputerName ComputerType State ConfigurationName Availability -- ---- ------------ ------------…

WordPress Plugin Syntax Highlighter Fix

Source: from a forum poster of this plugin's Github page. // Add this to functions.php…

PowerShell: Backup, Archive, and Remove a Microsoft SQL Database

$sqlServer='sqlsherver007' $databaseName="someDatabaseName" $saCredential=get-credential $backupDestination="\\Archive03\MSSQL_Backups" function triggerSqlBackup($sqlServer,$databaseName){ # Ensure the the Jump Box has SQL PowerShell…

PowerShell: Disable Annoying Windows Updates Notifications

This little snippet would render these notices as void. # This snippet is to add…

Function to Install Application and Its PowerShell Wrapper

# This function checks on whether a particular app has a corresponding PowerShell wrapper. If…

PowerShell: Automated Login Validation Using Internet Explorer

Update April 395 A.D.: IE variances make it difficult to perform standardized automation; hence, another…

PowerShell: Encapsulating Function Inside a Function and Inside an Invoke-Command or Job

$domain='google.com' function pingSomething($x){ $result=ping $x function getTraceroute($y){ pathping $y } $result+=getTraceroute $x return $result }…

Microsoft Dynamics CRM Permission Errors

Error Message: WARNING: Source : mscorlib Method : HandleReturnMessage Date : 3:00:50 PM Time :…

PowerShell: Run PowerShell As Another User

# Set credential $adminUsername='domain\adminDude' $adminPassword='whatpassword?' $GLOBAL:adminCredential=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminUsername,$(ConvertTo-securestring $adminPassword -AsPlainText -Force) # Test…

PowerShell: How to Send Key Strokes to a Program Graphical User Interface

# WARNING: there's a kill-process command when the target program is already running # so…

PowerShell: Adding a User to Local Groups

Adding User(s) to Local Groups # addUserToLocalGroup.ps1 # Version 0.02 $computernames=@( 'SERVER0001', 'SERVER0002' ) $accountsToAdd='domain\user1','domain\user2'…

PowerShell: Obtain Date Time Stamp And Convert to Pacific Standard Zone

# 1-liner date stamp $dateStamp=[System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId( (Get-Date), 'Pacific Standard Time').tostring("MM-dd-yyyy-HHmm")+'_PST' #sample output #06-15-2020-1949_PST $timeZone='Pacific Standard Time'…

PowerShell: Excute Function Remotely

$computername=$env:computerName $adminUsername='doeMainAdmin' $adminPassword='frackingPassword' $adminCredential=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminUsername,$(ConvertTo-securestring $adminPassword -AsPlainText -Force) function execFunctionRemotely{ param( [Parameter(Mandatory=$true)][string]$computerName,…

PowerShell: Install PSTools

if(!(get-command psexec -ea SilentlyContinue)){ if (!(Get-Command choco.exe -ErrorAction SilentlyContinue)) { Set-ExecutionPolicy Bypass -Scope Process -Force;…

PowerShell: Microsoft SQL Database Migration

Update 9/25/20: There's another version of this script has has been rewritten form scratch. IMO,…

PowerShell: Obtaining SQL Database Default Paths

# This function returns an array of 3 string values reflecting default Data, Log, and…

Loading the SQL Server Management Objects (SMO)

function loadSMO{ $ErrorActionPreference = "Stop" $sqlpsRegistry="HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps" try{ if (Get-ChildItem $sqlpsRegistry -ErrorAction "SilentlyContinue") { throw "SQL…

PowerShell: Replace 1 Line in a Text File Matching Certain Values

# replaceLine -textContent $fileContent -match $url -updateLineContent $record function replaceLine($textContent,$match,$updateLineContent){ $line = $textContent | Select-String…

PowerShell: Invoke-Command to Add A Host Record on DNS Server

# DNS Host Record Information $aRecord="superman" $recordIP='192.168.0.256' $zoneName='kimconnect.com' $dnsServer='dc01.intranet.kimconnect.com' # Admin Credential $adminUsername='DoeManeAdmin' $adminPassword='WhatPassword?' $adminCredential=New-Object…

PowerShell: Validate SQL Server Credentials

Add this to your SQL toolbox so that it'll be quick and easy to validate…