Category: Codes

List Autorun Services

# $cred = get-Credential -credential kdoan-a $Username = 'kimconnect\kim-Admin $Password = 'PASSWORD' $pass = ConvertTo-SecureString…

Last Logon Dates of List of AD Accounts

import-module activedirectory$output=""Get-Content C:\Users\kimconnect\Desktop\targetAccounts.txt | Foreach-Object -Process{ #  cast an array object as string before using…

Find Empty Directories

$directories="\\FILESERVER01\SHARE01" # Dynamic Credential method 1 $who = whoami if ($who.substring($who.length-2, 2) -eq "-admin"){$username=$who;} else…

SQL AlwayOn High Availability Default Port

Internal SQL DEV & QA environments may have SQL listening to the default port of…

PowerShell: Elevating Credential

$jumpbox="127.0.0.1" <# # Static Credentials (unsecured) $username = (Get-ADDomain).name+"\ADMINISTRATOR" $password = "PASSWORD" #> # Dynamic…

PowerShell: Disable NetBios

# Set Credentials $username = "KIMCONNECT\"+(Read-Host -Prompt 'Input the Admin Username: ') $password = Read-Host…

PowerShell: Convert String to Command

# Method 1 $command =@"ping google.com"@$scriptBlock = [Scriptblock]::Create($command)Invoke-Command -ComputerName localhost -ScriptBlock $scriptBlock# Method 2$xVariable="K1"$yVariable="ping"$commandString=$yVariable+" "+$xVariablefunction…

Check Whether an Entity Has Access to a Directory or Its Children

Write-Host "This script just be ran in the context of a File Server Administrators member"…

Check Servers NSLookup of a Listener to Match Active Node IP

$servers="SQL01","SQL02","SQL03","SQL04" $listener="halistener01" $activeNode="10.10.10.5" # Dynamic Credential method 1 $who = whoami if ($who.Substring($who.length-2, 2)="-admin"){$username=$who;} else…

Check a List of Servers to Find Currently Stopped Autorun Services

$username = (Get-ADDomain).name+'\USERNAME' $Password = 'PASSWORD' $pass = ConvertTo-SecureString -AsPlainText $Password -Force $cred = New-Object…

Add a Domain Group to Local Administrators Group

$checkGroup="Administrators" $addMember="KIMCONNECT\Desktop Admins" # Dynamic Credential $who = whoami if ($who.substring($who.length-2, 2) -eq "-admin"){$username=$who;} else…

Add Local Windows User

# Dynamic Credential$who = whoamiif ($who.substring($who.length-2, 2) -eq "-admin"){$username=$who;}else {$username=$who+"-admin";}$password = Read-Host -Prompt "Input the…

WinRM Management Consideration

Infrastructure needs to be able to leverage scripting automation to perform Vulnerability Remediation, Resource Provisioning,…

HaProxy RDP Forwarding

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp PortNumber = 000001BB frontend fe_rdp_tsc bind 0.0.0.0:443 name rdp_web ssl crt kimconnect.com.pem mode…

PowerShell: Simulate File Open Locking

# Simulate error by creating file in current directory with some contents; then, open file…

Set Permissions of NTFS/SMB Directories Recursively

# Set variables here$proxy="http://proxy:80"$directories="\\FILESERVER01\dept01$","\\FILESERVER01\dept02$"$grantAccess="KIMCONNECT\SysAdmins"$access="Full"# Run as$username = "kimconnect\kim"$password = "PASSWORD"#$username = "kimconnect\"+(Read-Host -Prompt 'Input the…

PowerShell Dealing with Proxy

# Direct Access - no proxy netsh winhttp reset proxy   # Set proxy $proxyString…

PowerShell Script to Copy Members of One Group to Another

#Author: Kim Doan#Please tell me this code suck so that I can improve # Adding…

How to Call Functions or Pass Function as Argument

cls   function listClusters{     # List all Clusters in this Domain     $items=get-cluster -domain (get-addomain)     $global:clusters=$items…

Apache Multiple Domains Config

vim /ect/httpd/conf/httpd.conf <VirtualHost *:80>      ServerAdmin [email protected]      ServerName kimconnect.com      ServerAlias www.kimconnect.com      DocumentRoot…