Category: Codes

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…

PowerShell: Outdated Method of Sending Emails

# Credentials section $emailFrom = "[email protected]" $password = "eatYourSalad!" | ConvertTo-SecureString -AsPlainText -Force # plaintext…

BASH: Basic AWK Training

At first, AWK resembles the first three letter of 'awkward'. Nope, it's a scripting language…

PowerShell: Reset Password for All Users inside an OU

$ouName="Funky Dudes" $ouPath = "ou=$ouName,dc=intranet,dc=baam,dc=com" $plaintextPassword='WHATPASSWORD?' $users=Get-ADUser -Filter * -SearchBase $ouPath | Select-object Name,UserPrincipalName,DistinguishedName foreach…

Linux: How to Set Startup Script

In previous Linux versions, startup scripts can simply be enabled by linking a script into…

PowerShell: Send Email Notifications to Computer Users Before Maintentance

# sendEmailToUsers.ps1 # Query Active Directory for computers running a Server operating system #$targetServers =…

PowerShell: How to Create Multiple Arrays or Columns from an Array

# This snippets scans the localhost for common ports and outputs 4 arrays $limitPorts=10000 $netstat=netstat…

PowerShell: Inter-Domain SMB Shares Mounting

# interDomainFileCopy.ps1 # Note: this is a quick and dirty method. Password security must be…

PowerShell: Detect Whether Computer is Connected To Domain

# The easy method $domainConnected=.{ try { [void]::([System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()) return $true } catch{ return $false }…

Linux: Use Lubuntu 20.04, TightVNC Server, NoVNC, WebSockify to Create a Terminal Server Accessible via Any Browser!

Use Case:Imagine a virtual classroom with students using Chromebooks, iPads, and other types of computers,…

How to Enable GPUPDATE When Connected via OpenVPN Client

// Explanation: to prevent locking of processes, we set a proxy batch file (on_connect.bat) to…

PowerShell: Disable Forticlient Web Filtering

# disableForticlientWebfiltering.ps1 # Note: untested script - use as sample as this snippet is incomplete…