Skip to content

Instantly share code, notes, and snippets.

Avatar

Marc Kean marckean

  • Microsoft
  • Sydney, Australia
  • Twitter @marckean
View GitHub Profile
View PowerShellAzureFunction.ps1
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
$FirstName = $Request.Query.FirstName # Query based parameters
View Calling PowerShell Azure Functions v2.ps1
#########################################################
####### only works if the Route template is blank #######
#########################################################
# QUERY based parameter values - GET method
$firstName = 'Marc'
$surName = 'Kean'
$iwr = Invoke-WebRequest -Uri "https://ejuke2.azurewebsites.net/api/blog?firstname=$firstName&surname=$surName" -Method Get
$iwr.content
View Azure - Back up and restore Azure file shares.ps1
<#
Written with version 1.3.0 of the Az PowerShell Module
Run Get-InstalledModule to check installed modules
Install PowerShell Core 6 https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-windows?view=powershell-6
The Az PowerShell Module is available from here https://github.com/Azure/azure-powershell/releases/tag/v1.4.0-February2019
... or run: Install-Module -Name Az -RequiredVersion 1.4.0 -AllowClobber
View Connect to WiFi network, using password.ps1
# Fill in mandatory details for the WiFi network
$WirelessNetworkSSID = '<WiFi_SSID>'
$WirelessNetworkPassword = '<WiFi_password>'
$Authentication = 'WPA2PSK' # Could be WPA2
$Encryption = 'AES'
# Create the WiFi profile, set the profile to auto connect
$WirelessProfile = @'
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>{0}</name>
View AzureFunctions_PowerShell_Output HTML.ps1
# Setup the Azure Functions parameters
# https://marcfunction1.azurewebsites.net/api/sca/scanowplaying?state={state}
switch -RegEx ($REQ_QUERY_STATE)
{
\S {$state = $REQ_QUERY_STATE}
# https://marcfunction1.azurewebsites.net/api/sca/{state}
default {$state = $REQ_PARAMS_STATE}
}
View Windows 10 Adaptive Contrast.ps1
# Turn adaptive contrast on - default
$value = '9240'
New-ItemProperty -Path 'HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0001' `
-Name 'FeatureTestControl' -PropertyType DWORD -Value $value -Force
# Turn adaptive contrast off
$value = '9250'
New-ItemProperty -Path 'HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0001' `
-Name 'FeatureTestControl' -PropertyType DWORD -Value $value -Force
View Resource_Group_tags_to_children.ps1
##########################################################################################
###################### To be used with an Azure Automation runbook
###################### make sure you create the Automation Credential -Name 'AzureRunAsConnection'
###################### make sure you Automation Variable -Name 'SubscriptionID'
######################
##########################################################################################
# Thanks to https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-using-tags
$ServicePrincipalConnection = Get-AutomationConnection -Name 'AzureRunAsConnection'
View ShutdownDevTestVMs - Logic App.json
{
"$connections": {
"value": {
"azureautomation": {
"connectionId": "/subscriptions/6bb00255-5486-4db1-96ca-5baefc18b0b2/resourceGroups/OutlookApprovalLogic/providers/Microsoft.Web/connections/azureautomation",
"connectionName": "azureautomation",
"id": "/subscriptions/6bb00255-5486-4db1-96ca-5baefc18b0b2/providers/Microsoft.Web/locations/australiaeast/managedApis/azureautomation"
},
"office365": {
"connectionId": "/subscriptions/6bb00255-5486-4db1-96ca-5baefc18b0b2/resourceGroups/OutlookApprovalLogic/providers/Microsoft.Web/connections/office365",
View LogicApps Stop-Azure-VMs-Parameter.ps1
param
(
[parameter(Mandatory=$true)]
[String] $VMnames
)
$ServicePrincipalConnection = Get-AutomationConnection -Name 'AzureRunAsConnection'
$null = Add-AzureRmAccount `
-ServicePrincipal `
View LogicApps Get-All-VMs.ps1
$ServicePrincipalConnection = Get-AutomationConnection -Name 'AzureRunAsConnection'
$null = Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $ServicePrincipalConnection.TenantId `
-ApplicationId $ServicePrincipalConnection.ApplicationId `
-CertificateThumbprint $ServicePrincipalConnection.CertificateThumbprint
##################################################################
##################################################################