Skip to content

Instantly share code, notes, and snippets.

View brettmillerb's full-sized avatar
🏠
Working from home

Brett Miller brettmillerb

🏠
Working from home
View GitHub Profile
# Define an array of services
$services = 'service1','service2','service3','service4'
# Iterate through each item in the array
foreach ($service in $services) {
# Get the service and save it to the variable
$serviceObj = Get-Service -Name $service
# if the variable is present - An If statement returns a bool value
if ($serviceObj) {
function Enter-PSCmdletContext { [CmdletBinding()]param() $Host.EnterNestedPrompt() },
Enter-PSCmdletContext
$PSCmdlet
$TAType = [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")
$TAType::Add('accelerators',$TAType)
# this now works
[accelerators]::Add()
function Get-ShadowStorageSpace {
[CmdletBinding()]
param (
[Parameter(Mandatory,
Position = 0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[string[]]
$ComputerName
)
@brettmillerb
brettmillerb / phonesanitisation.ps1
Created November 13, 2018 11:25
Script to format mobile numbers in Active Directory
#Get's all enabled users from the all users group which is populated nightly.
$usersall = Get-ADUser -Filter *
#Declare pattern match to remove non integer characters.
$numpattern = '[^0-9]'
#Iterate through users applying replaced value
$users | ForEach-Object {
$regexedmobile = $_.mobile -replace $numpattern,''
$userobj = [pscustomobject]@{
@brettmillerb
brettmillerb / MSTeams.ps1
Created November 28, 2018 16:44
MicrosoftTeams module wrapper functions
function New-MsTeamsChannel {
[cmdletbinding(DefaultParameterSetName = 'Input')]
param (
[Parameter(Mandatory,
Position = 0,
ValueFromPipeline,
ValueFromPipelineByPropertyName,
ParameterSetName = 'Input')]
[string[]]
$DisplayName,
@brettmillerb
brettmillerb / pageDutyTeamLog.txt
Created December 10, 2018 14:45
tfPagerDutyLogs
2018/12/10 14:44:27 [INFO] Terraform version: 0.11.10 17850e9a55d33c43d7c31fd6ac122ba97a51d899
2018/12/10 14:44:27 [INFO] Go runtime version: go1.11.1
2018/12/10 14:44:27 [INFO] CLI args: []string{"C:\\Program Files\\terraform\\terraform.exe", "plan"}
2018/12/10 14:44:27 [DEBUG] Attempting to open CLI config file: C:\Users\brett.miller\AppData\Roaming\terraform.rc
2018/12/10 14:44:27 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2018/12/10 14:44:27 [INFO] CLI command args: []string{"plan"}
2018/12/10 14:44:27 [INFO] command: empty terraform config, returning nil
2018/12/10 14:44:27 [DEBUG] command: no data state file found for backend config
2018/12/10 14:44:27 [DEBUG] New state was assigned lineage "b9a87e1d-da03-8cf9-fae1-6834b2e6e4ad"
2018/12/10 14:44:27 [INFO] command: backend initialized: <nil>
@brettmillerb
brettmillerb / Git-Whoami.ps1
Created January 14, 2019 14:28
Git Whoami
# Stolen from here: https://github.com/petere/git-whoami/blob/master/git-whoami
function Git-Whoami {
$author = git config user.name
$email = git config user.email
[pscustomobject]@{
Author = $author
Email = $email
}
}
@brettmillerb
brettmillerb / UsefulGitCommands.md
Last active January 18, 2019 12:01
Git commands
{
"files.defaultLanguage": "powershell",
"window.zoomLevel": -1,
"editor.renderWhitespace": "all",
"powershell.integratedConsole.focusConsoleOnExecute": false,
function Get-MsTeamsGroupId {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,
Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]
$TeamName