Skip to content

Instantly share code, notes, and snippets.

View marckean's full-sized avatar

Marc Kean marckean

View GitHub Profile
# Switch to the Azure AzureRM PowerShell module
if(Get-Module -Name Az*){
Remove-Module -Name Az*
Import-Module -Name AzureRM -Force}
# Switch to the Azure AZ PowerShell module (
if(Get-Module -Name AzureRM*){
Remove-Module -Name AzureRM*
Import-Module -Name Az -Force}
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
#########################################################
####### 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
<#
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
# 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>
# 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}
}
# 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
##########################################################################################
###################### 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'
{
"$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",
param
(
[parameter(Mandatory=$true)]
[String] $VMnames
)
$ServicePrincipalConnection = Get-AutomationConnection -Name 'AzureRunAsConnection'
$null = Add-AzureRmAccount `
-ServicePrincipal `