Skip to content

Instantly share code, notes, and snippets.

View janegilring's full-sized avatar

Jan Egil Ring janegilring

View GitHub Profile
@janegilring
janegilring / Packer-Windows.json
Created April 27, 2018 05:42
Packer file for building Windows base images
{
"builders": [
{
"type": "hyperv-iso",
"output_directory": "./output-{{ user `os_name` }}-base-hyperv/",
"temp_path": "C:\\ClusterStorage\\HYPData01\\PackerTemplates\\temp",
"vm_name": "{{ user `os_name` }}-base",
"iso_url": "{{ user `iso_url` }}",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_checksum_type": "sha1",
@janegilring
janegilring / dashboard.ps1
Created November 16, 2017 19:53
Example dashboard for taking input and performing actions - built with PowerShell Universal Dashboard (https://poshtools.com/powershell-universal-dashboard)
#requires -Modules UniversalDashboard
$Colors = @{
BackgroundColor = "#FF252525"
FontColor = "#FFFFFFFF"
}
Start-UDDashboard -Content {
New-UDDashboard -Title "Employee registration form" -NavBarColor '#FF1c1c1c' -NavBarFontColor "#FF55b3ff" -BackgroundColor "#FF333333" -FontColor "#FF55b3ff" -Pages @(
New-UDPage -Url "/register/:id" -Endpoint {
@janegilring
janegilring / Set-MailboxAutoReplyConfiguration.ps1
Created November 5, 2017 13:58
Set-MailboxAutoReplyConfiguration runbook for use with Azure Automation
param (
[string]$UserName
)
# Credential for the user mailbox to configure Out-of-office schedule for
$UserCredential = Get-AutomationPSCredential -Name $UserName
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
$EXOModule = Import-PSSession $Session
@janegilring
janegilring / Set-MailboxAutoReplyConfiguration.ps1
Created November 5, 2017 13:40
Set-MailboxAutoReplyConfiguration demo
# Credential for the user mailbox to configure Out-of-office schedule for
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
$EXOModule = Import-PSSession $Session
# Customize as needed - for example, setup as parameters for a function/script
$StartTime = Get-Date 08:00
$EndTime = Get-Date 16:00
# Credential for the user mailbox to configure Out-of-office schedule for
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
$EXOModule = Import-PSSession $Session
Get-Command -Module $EXOModule.Name
Get-Command -Module $EXOModule.Name | Format-Wide -Property Name -AutoSize
@janegilring
janegilring / Invoke-UserOffboarding.ps1
Last active July 12, 2021 17:45
Sample user offboarding runbook for Azure Automation for initiating device factory reset for all of a users devices as well as deleting the user
param(
$UserPrincipalName
)
try {
Import-Module -Name AzureAD -ErrorAction Stop
Import-Module -Name MSGraphIntuneManagement -ErrorAction Stop
@janegilring
janegilring / MSGraphIntuneManagement-demo.ps1
Last active October 30, 2017 07:03
Installation and sample usage of the MSGraphIntuneManagement PowerShell module
# Install the module from the PowerShell Gallery
Install-Module -Name MSGraphIntuneManagement
# After installation, you can view available commands by using Get-Command:
Get-Command -Module MSGraphIntuneManagement
# Get an access token which can be leveraged for authenticating to the Microsoft Graph API for performing operations against the Intune service
$Credential = Get-Credential
$ClientId = '34d24e43-0ae1-4ed4-bdea-444073711c55'
$Token = Get-MSGraphAuthenticationToken -Credential $Credential -ClientId $ClientId
# Dot source the function (optimally - place it in a module)
. C:\Scripts\Get-MSGraphAuthenticationToken.ps1
# Define client ID for an Azure AD Application with necessary permissions against the Microsoft Graph API
$ClientID = "1950a258-227b-4e31-a9cf-717495945fc2"
# Credentials for the user who should be used for authentication
$Credential = Get-Credential
# Generate an access token
@janegilring
janegilring / Find-BabyName.ps1
Created September 20, 2017 17:00
Quickly written PowerShell function for finding Norwegian baby names
# Guttenavn
$maledata = Invoke-WebRequest -Uri 'https://www.ssb.no/statistikkbanken/selectvarval/define.asp?SubjectCode=01&ProductId=01&MainTable=FornavnPersoner&contents=Personer&PLanguage=0&Qid=0&nvl=True&mt=1&pm=&SessID=3980226&FokusertBoks=1&gruppe1=Hele&gruppe2=Hele&VS1=NavnMenn01&VS2=&CMSSubjectArea=befolkning&KortNavnWeb=navn&StatVariant=&Tabstrip=SELECT&aggresetnr=1&checked=true'
# Jentenavn
$femaledata = Invoke-WebRequest -Uri 'https://www.ssb.no/statistikkbanken/selectvarval/define.asp?SubjectCode=01&ProductId=01&MainTable=FornavnPersoner&contents=Personer&PLanguage=0&Qid=0&nvl=True&mt=1&pm=&SessID=3980226&FokusertBoks=1&gruppe1=Hele&gruppe2=Hele&VS1=NavnKvinner01&VS2=&CMSSubjectArea=befolkning&KortNavnWeb=navn&StatVariant=&Tabstrip=SELECT&aggresetnr=1&checked=true'
$malenames = @()
$maledata.ParsedHtml.getElementsByTagName("OPTION") | foreach {$malenames += $_.text}
@janegilring
janegilring / PSProductivityTools-example.ps1
Created August 24, 2017 19:58
Example usage of the PSProductivityTools PowerShell module
# Initiates a new Pomodoro sprint, defaulting to 25 minutes duration.
Start-Pomodoro
# Initiates a new Pomodoro sprint with 10 minutes duration. A random audio-file will be started from the specified audio file path
Start-Pomodoro -Minutes 10 -AudioFilePath ~\Music\MusicToCodeByCollection -StartMusic
# Initiates a new Pomodoro sprint. A mobile device can be muted when starting the sprint and unmuting when the sprint is finished by using IFTT webhooks.
Start-Pomodoro -IFTTMuteTrigger start_pomodoro -IFTTUnMuteTrigger stop_pomodoro -IFTTWebhookKey abcdef
# In order to avoid having to specify a lot of parameters (we want to be productive, right?), a tip is to specify static information by using default parameter values (available in PowerShell 3.0 and later). Open your PowerShell profile (psedit $profile) and use the following syntax: