Month: July 2020

SQL: Using PowerShell to Check if a Table, View, or Stored Procedure Exists

#Usage # set variables $sqlServer='sql-server04' $databaseName="Test_Database" $objectType='view' $objectName='[dbo].[Test_View]' $saCred=get-credential # Call function checkDatabaseObject $sqlServer $databaseName…

PowerShell: Taking a Snapshot of a Windows Volume

I have this snippet embedded in various programs. Perhaps, it's useful to be posted as…

Microsoft Dynamics – Selecting an Org

# These two functions are convenient for CRM admins to quickly gather a hosted organization…

PowerShell: HashMap Enumeration Example – Set Active-X on Internet Explorer

function allowActiveX($zone='Trusted'){ #Source: http://support.microsoft.com/KB/182569 #Reference table: #Value Setting #------------------------------ #0 My Computer #1 Local Intranet…

Update Host Files on Multiple Servers

$arecord='intranet' $domain='contoso.com' $serverIp='555.555.555.555' $groupTag='# Accounting Servers' $serversToEdit='Accounting1','Accounting2','Watermelon' $commentOut=$false function updateHostFiles{ param( $appLocalIp, $orgName, $domain, $searchString,…

Microsoft SQL Database Stuck in Restoring Mode

These are the possible resolutions from highest to lowest recommendations -- Normal method of restoring…

PowerShell: Sorting an Array of Strings as Numbers

This is a useful function to sort a list of computer names. The built-in sorting…

PowerShell: Coverting Hex or Bytes Array to ASCII

The following is an illustration of a practical usage of decrypting an ASCII encoded value…

Create a Report of MTU Settings on All Hyper-V Hosts in the Domain/Forest

# mtuReportAllHyperVHosts.ps1 # Ensure that AD management module is available for PS Session function includeRSAT{…

Enable Jumbo Frames on a Windows Host

Overview: Whether the engineer or sysadmin works in the realm of 'networking', 'database', or 'Windows',…

Quick Script to Test SharePoint Online Credentials

$principle = "[email protected]" $password = 'PASSW0RT' $sharePointUrl = "https://SOMESHAREPOINT.COM/SitePages/Home.aspx" $credential=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $principle,$(ConvertTo-securestring $password…

Installing Linux Kernel on Windows 10 Machines

# installLinuxOnWindows10.ps1 # Please don't try to run this on target OS Windoze XP or…

Hyper-V: De-register Storage File Share and/or Removing Paths from VMM

# vmmDeregisterFileSharePath.ps1 $pathSearch='\\DECOMMISSIONED-FILESHARE008' $unregister=$true $remove=$false $fileShares=Get-SCStorageFileShare|?{$_.SharePath -like "*$pathSearch*"} $thisLibraryServer = Get-SCLibraryServer if($unregister){$fileShares|%{Unregister-SCStorageFileShare -StorageFileShare $_ -LibraryServer…

Hyper-V: Search for Guest VMs Utilizing Certain Storage Paths

$pathSearch='C:\ClusterShare\RandomFolder' $pathSearch='C:\ProgramData' $allHyperVHosts={(Get-ClusterNode | Where { $_.State –eq "Up" }).Name | %{$_.ToLower()}}.Invoke() $allVms=foreach ($hyperVHost in…

PowerShell: Audit Failed Logins of A User

$username='rambo' function auditLockouts($userName,$domainController,$refreshMinutes=1){ function getLockouts($domainControler){ # Requirement: # Domain Controllers Audit Group Policy has been…

How to discover WSUS Server from Your Local Machine

# Method 1: PowerShell (the obvious choice) (Get-ItemProperty HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate).WuServer # Method 2: Command Line REG…

PowerShell: Create SMB Share and Grant NTFS Access

$localPath="C:\testShare" $fullAccessAccounts='everyone','authenticated users' function createSmbShare($localPath,$fullAccessAccounts){ $ErrorActionPreference='stop' try{ # First, create SMB Share $smbShareName=split-path $localPath -leaf…

WinRM Issues Caused by Service Principal Name (SPN) HTTP Protocol & Port Associations

Solution as Code: There is no easy solution to this problem. Certain IIS Pool Accounts…

Using Telnet and PowerShell to Test SMTP Relay

PowerShell Method: Example of Failure: PS C:\> sendTestEmail '[email protected]' 'password' '[email protected]'Detected MX Record : ywpjf4z5siycosmh7uqymtuygcjehuc67wa6o4rq4k2a3g2aodma.mx-verification.google.comKnown…

PowerShell: Add Root Domain to Trusted Sites

Windows Servers often have 'hard admin' modes, where accesses to external websites are painstakingly restricted.…