Category: Codes

PowerShell: Microsoft Exchange Admin Reports

Function importExchangeModule{ $snapinLoaded = (get-pssnapin microsoft.exchange.management.* -ErrorAction SilentlyContinue).Name $exchangeVersion=(GCM Exsetup.exe | % {$_.FileVersionInfo}).ProductVersion $exchangeVersionMajor=$exchangeVersion.Substring(0,2); $exchangeVersionMinor=$exchangeVersion.Substring(3,2);…

PowerShell: Obtain Domain Admin Credential and Save It as an XML for Subsequent Execution

Working Version: # Initialize with defaults$credFileExists=$False# This function is a workaround to the issue of…

PowerShell: Detect Windows Version

This little snippet is reusable on many occasions where Windows version targeting is required. function…

Barracuda Message Archiver & Office 365 Exchange Online Service Account Configuration

The following script grant an Office 365 Exchange online service account necessary permissions on Exchange…

PowerShell: Find Azure AD Connect Servers From On-remise AD

Azure AD Connect is a prevalent topic of the day. However, it is best practice…

PowerShell: Command Line to Empty a Remote Directory

PowerShell Method $remoteUncPath="\\FILESHERVER01\FOLDER01"$emptyDirectory="C:\emptyDirectory"md -Force $emptyDirectoryRemove-Item "$emptyDirectory`\*" -force -recurse -ErrorAction Continuerobocopy $emptyDirectory $remoteUncPath /mir /R:0 /W:0…

PowerShell: Obtain Domain Admin Credential

This little snippet is reusable as an appendix to other scripts since Domain Admin access…

PowerShell: Install Windows Cluster Admin

# Install Microsoft Clustering ManagementFunction installClusteringManagment{ # Set PowerShell Gallery as Trusted to bypass prompts…

PowerShell: Discover Environment

One of the most common tasks of Active Directory cleanup is to perform a discovery…

PowerShell: Script to Apply Windows Update on 2016 Server

8/7/2020: there's a more updated version available here. # Update-Remote-Windows-2016-Servers.ps1$servers="SERVER1","SERVER2"function applyWindowsUpdates{ [CmdletBinding()] param ( [parameter(Mandatory=$true,Position=1)]…

PowerShell: Hyper-V Management

Migrate Live Virtual Machines (In Clustered Environment): # Connect to Hyper-V Host$remoteHost="HYPERV01"Enter-PsSession $remoteHost # Move…

Windows: Enable Remote Access

# Set remote hostname variable$remoteHost="HV01"# Install psexecInstall-Module -Name psexec# psexec \\$remoteHost reg add "HKLM\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters" /v…

PowerShell: Perform DISM Restore Health on Remote Servers

# This script will use a Windows ISO image to Repair Remote Computers$isoPath="\\FILESHERVER007\F$\Windows_Server_2016_Datacenter_EVAL_en-us_14393_refresh.ISO"$remoteComputers="TESTKOMPUTER","TESTKOMPUTER2"function restoreServerHealth($iso){ #…

Enable WinRM Remotely

Usage:enableWinRm 'RemoteServer' get-credential $remoteComputer='REMOTESERVER' $winRmPort=5985 $adminCredential=get-credential function enableWinRm($remoteComputer,$winRmPort=5985,$adminCredential){ function Check-NetConnection($computername,$port,$timeout=200,$verbose=$false) { $tcp = New-Object System.Net.Sockets.TcpClient;…

PowerShell: Install and Uninstall App on Remote Machines

# Trigger uninstall of an MSI file$computername="SERVER007"$keywordSearch="Polycom*"$installFile="\\FILESHERVER\Software\Polycom\Polycom_BToE_Connector_4.0.0.0 (new for 2019-07-19)\Polycom_BToE_Connector_4.0.0.0.msi"# Trigger silent install of an…

PowerShell: Use Regex to Select IPv4 Patterns

# This example shows how to obtain ip address of the $env:logonserver$logonServerIP=nltest /DSGETDC:$regexIP = [regex]…

PowerShell: Replicate All Domain Controllers Immediately

<#Author: KimConnect.comVersion: 0.1Purpose:- After a change has been issued against a "logon server", that domain…

Script to Deploy Executables

set InstallRevision=1.0set TargetDir="%ProgramFiles%\Program Name"REM Check to see if the software has been installed. Check for…

PowerShell: Send Private Message to Another Computer

$name = read-host "Enter remote computer name "$messageInput = read-host "Enter your message to send…

PowerShell: Connect to Azure CLI

# Set PSGallery as trusted to bypass promptsSet-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted -WarningAction SilentlyContinue #…