Author: kimconnect

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…

PowerShell: Error Unable to find package provider ‘NuGet’ Resolved

How to install module in Powow Shill Current Version: $moduleCommand='New-SSHSession' $moduleName='Posh-SSH' if(!(get-command $moduleCommand -ea Ignore)){…

PowerShell: Convert Local Path to UNC Path

function convertLocalToUnc($localPath,$computername){ $uncPath=.{$x=$localPath -replace "^([a-zA-Z])\:","\\$computername\`$1`$"; if($x -match '\\$'){return $x.Substring(0,$x.length-1)}else{return $x} } $validLocal=if($localPath){test-path $localPath -ErrorAction SilentlyContinue}else{$false}…

PowerShell: Stream Reader

Have you ran into scripting situations where opening a file would result in locking from…

PowerShell: Mount A Remote SMB/CIFS/NFS Share as a Specific User

This function is useful in scenarios where a separate user account is needed to mount…

PowerShell: Deploy Choco Apps

Deployment Instructions: Create a batch file with this content to call this PowerShell Script @echo…

Windows Group Policy: Set Chrome as Default with a Home Page

Opinion: So... your company wants to standardize on Chrome, eh? I must say that I…