Skip to content

Instantly share code, notes, and snippets.

View marckean's full-sized avatar

Marc Kean marckean

View GitHub Profile
##########################################################################################
###################### 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",
$ServicePrincipalConnection = Get-AutomationConnection -Name 'AzureRunAsConnection'
$null = Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $ServicePrincipalConnection.TenantId `
-ApplicationId $ServicePrincipalConnection.ApplicationId `
-CertificateThumbprint $ServicePrincipalConnection.CertificateThumbprint
##################################################################
##################################################################
param
(
[parameter(Mandatory=$true)]
[String] $VMnames
)
$ServicePrincipalConnection = Get-AutomationConnection -Name 'AzureRunAsConnection'
$null = Add-AzureRmAccount `
-ServicePrincipal `
$ServicePrincipalConnection = Get-AutomationConnection -Name 'AzureRunAsConnection'
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $ServicePrincipalConnection.TenantId `
-ApplicationId $ServicePrincipalConnection.ApplicationId `
-CertificateThumbprint $ServicePrincipalConnection.CertificateThumbprint
##################################################################
##################################################################
### Variables
$dropboxDBfile = Get-ChildItem -Path $env:USERPROFILE\AppData\Local -Recurse -ErrorAction SilentlyContinue | ? {$_.Name -eq 'host.db'}
$base64path = gc $dropboxDBfile.FullName | select -index 1
$dropboxPath = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($base64path)) # convert from base64 to ascii
$taskName = "Keep_WiFi_Connected"
$Path = 'PowerShell.exe'
$Arguments = "-ExecutionPolicy Unrestricted -File c:\StartLTE-WiFi.ps1"
$Service = new-object -ComObject ("Schedule.Service")
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"metadata": {
"description": "Deployment location"
},
"defaultValue": "australiaeast"
#region Install Modules
# Run as Administrator
#Find-Module AzureServicePrincipalAccount | Install-Module
#endregion
# Retrieve Azure Module properties
""
"Validating installed PowerShell Version and Azure PowerShell Module version..."
# Replace with your Workspace ID
$CustomerID = $REQ_PARAMS_LogAnalyticsCustomerID
# Replace with your Log Analytics workspace Primary Key
$SharedKey = $REQ_PARAMS_LogAnalyticsPrimaryKey
#Specify the name of the record type that we'll be creating.
$LogType = $REQ_PARAMS_LogType # To be used to search for as a custom log e.g. Type=iTunesPopCharts2_CL
# Specify a time in the format YYYY-MM-DDThh:mm:ssZ to specify a created time for the records
$TimeStampField = ''
# Telstra DEV APIs - https://dev.telstra.com
$Telstra_app_key = $REQ_PARAMS_Telstra_app_key
### RUN AS ADMINISTRATOR
# This script here string, will be copied to the local computer to be run locally
# Change the variables in this script, they are at the top in this here string
$script = @'
# Testing, $args is an array object ($args | Out-File "C:\Scripts\PerformanceAlert.txt" –Append)
#########################################
# Replace with your Workspace ID
$LogAnalyticsCustomerID = "Workspace ID"