Skip to content

Instantly share code, notes, and snippets.

View cyberautomate's full-sized avatar

cyberautomate

View GitHub Profile
# Basic Syntax example
Get-Service | Where-Object Status -eq Running
# Advanced Syntax example
Get-Service | Where-Object {$PSItem.Status -eq 'Running' -and $PSItem.StartType -eq 'Automatic'}
# Same as above
Get-Service | Where-Object {$_.Status -eq 'Running' -and $_.StartType -eq 'Automatic'}
# Enable Remoting to an Azure VM
Enable-PSRemoting
# Make sure to set the Public IP address to static or make sure you track the change of the public IP
# Create Network Security Group Rule to allow winrm
# Create a Selfsigned cert on the Azure VM
$Cert = New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName PC1.mydomain.local
Export-Certificate -Cert $Cert -FilePath '<filepath>\exch.cer'
# This is the script we'll run on a regular basis
# Get the filehash of the CurrentDomainAdmins.xml
$CurrentAdminsHash = Get-FileHash -Path 'C:\scripts\CurrentDomainAdmins.xml' |
Select-Object -expandProperty Hash
# Get the current date
$Date = Get-Date
# This is the file we're testing the CurrentDomainAdmins.xml file against
$newAdmins = 'c:\scripts\NewAdmins.xml'
# A variable we will use in the if statement below
# Run this once to get the Domain Admins group baseline
Get-ADGroupMember -Server signalwarrant.local -Identity "Domain Admins" |
Select-Object -ExpandProperty samaccountname |
Export-Clixml -Path 'C:\scripts\CurrentDomainAdmins.xml'
Function New-AzureLab {
<#
SYNOPSIS
New-AzureLab will create 1 or multiple VMs in Azure based on input parameters from a CSV
DESCRIPTION
Create a CSV file like below:
VMName,Location,InterfaceName,ResourceGroupName,VMSize,ComputerName
SP,EastUS,SP_Int,SignalWarrant_RG,Basic_A2,SP
The function will read the input from the CSV file and create VMs in an Azure Resource Group
Function Merge-PDFs {
<#
SYNOPSIS
Merges PDF files into 1 PDF file.
PARAMETER filePath
-filePath: Any PDF file in the filepath will be combined into 1 PDF file named All_PowerShell_Help.pdf.
PARAMETER dllPath
-dllPath: The Path to the iTextSharp.DLL file
##############################################################
# Merges all the PDF files for each Module in to 1 PDF file per
# module called Help_<moduleName>.pdf in $filepath
##############################################################
$folders = Get-ChildItem -Path $filePath -Directory
$ErrorActionPreference = 'silentlycontinue'
foreach ($folder in $folders){
$pdfs = Get-ChildItem -Path $folder.fullname -recurse -Filter '*.pdf'
Function Export-PShelp {
<#
SYNOPSIS
Exports the -full help for each CMDlet available on your computer.
DESCRIPTION
Gets all the Modules available on the computer, loops through those Modules to retrieve each CMDlet name as well as create a folder for each module. Loops through each CMDlet in each module and exports the -full help for each to the $filepath\$modulename
PARAMETER filePath
-filePath: The folder that you're exporting all the help files to on your local hard drive.
@cyberautomate
cyberautomate / ConverTo-PDF.ps1
Last active December 17, 2021 20:40
ConvertTo-PDF.ps1
Function ConvertTo-PDF {
<#
DESCRIPTION
Convert 1 or many files to PDFs
PARAMETER filePath
-filePath: The path to the folder that contains all your text files
PARAMETER dllPath
-dllPath: The Path to the iTextSharp.DLL file
# Run on the target node
[DSCLocalConfigurationManager()]
Configuration LCMConfig {
Node SVR {
Settings {
ConfigurationMode = 'ApplyAndAutoCorrect'
RefreshMode = 'Pull'
}
ConfigurationRepositoryWeb PullServer {