Skip to content

Instantly share code, notes, and snippets.

View tylerapplebaum's full-sized avatar
☁️
AWS + Networking

Tyler Applebaum tylerapplebaum

☁️
AWS + Networking
View GitHub Profile
@tylerapplebaum
tylerapplebaum / UnFUBAR-Service.ps1
Last active June 4, 2018 16:47
Kill Windows services in the Stop Pending state; Logs to Event Viewer
#Checks the status of $ServiceName and kills it if in the 'Stop Pending' state.
#Creates an event log; logs results to it
#Get-Random (Get-Service | Select-Object -ExpandProperty Name) | Kill-HungService -Verbose
Function script:Kill-HungService {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$True,Mandatory=$True,HelpMessage="Service to search for")]
[string]$script:ServiceName
)
@tylerapplebaum
tylerapplebaum / Invoke-Credentials.ps1
Last active March 26, 2018 09:19
A function to encrypt a credential object with a static key to allow for easy retrieval. It's recommended to lock down the credential folder with appropriate NTFS permissions, as the password file can be read back using the key stored in the script.
Function script:Invoke-Credentials {
[CmdletBinding()]
param(
[Parameter(HelpMessage="Specify the username for the stored credential")]
[ValidateNotNullOrEmpty()]
[string]$Script_Username = "svc.username", #Username goes here
[Parameter(HelpMessage="Specify the path to store the credential")]
[ValidateNotNullOrEmpty()]
[string]$Script_CredFolder = "C:\Automate\",
<#
.SYNOPSIS
Backup-CiscoConfig.ps1 SSHs to a Cisco device and backs up the running configuration to a TFTP server.. Utilizes the Posh-SSH module.
.DESCRIPTION
This script is not possible without darkoperator's Posh-SSH module. Thanks!
To do: Parameterize the device list. 10/05/16
Grab the output of long commands by setting the terminal length to 0 to disable pagination. "term len 0"
Log commands entered on the Cisco device to ensure they're running:
@tylerapplebaum
tylerapplebaum / Convert-ToBase64
Last active January 3, 2018 18:11
A function to convert a string to base64 encoding
Function Convert-ToBase64 {
param(
[CmdletBinding()]
[Parameter(ValueFromPipeline=$True,Mandatory=$True,HelpMessage="String to encode to base64")]
[ValidateNotNullOrEmpty()]
$String
)
$StringToByteArr = [System.Text.Encoding]::UTF8.GetBytes($String) #Converts string to byte array
$Base64String = [System.Convert]::ToBase64String($StringToByteArr) #Converts byte array to b64 string
@tylerapplebaum
tylerapplebaum / Get-StringHash
Last active January 3, 2018 18:11
A function to get the secure hash of a string
Function Get-StringHash {
param(
[CmdletBinding()]
[Parameter(ValueFromPipeline=$True,Mandatory=$True,HelpMessage="String to hash")]
$String,
[Parameter(HelpMessage="Hash algorithm")]
[ValidateSet('MD5','RIPEMD160','SHA1','SHA256','SHA384','SHA512')]
$Algorithm = "SHA1"
)
$StringBuilder = New-Object System.Text.StringBuilder
@tylerapplebaum
tylerapplebaum / Get-UserGroups.ps1
Last active January 3, 2018 18:10
Enumerate user groups
Function Get-UserGroups {
<#
.EXAMPLE
PS C:\> Get-UserGroups -GroupName "Domain Admins"
.EXAMPLE
PS C:\> [bool](Get-UserGroups -GroupName "Domain")
.EXAMPLE
PS C:\> Get-UserGroups -UserName elliot.alderson@e-corp-usa.com