Detecting and Launching PowerShell with Elevated Administrator Rights

Here is a good reference on detecting whether a PowerShell script is currently running with Administrator rights, and relaunching with elevated permissions if not. Courtesy of Bruno Saille’s JEA Helper Tool 2.0: https://gallery.technet.microsoft.com/JEA-Helper-Tool-20-6f9c49dd ######################################################################################## #Make sure we run elevated, or relaunch as admin ######################################################################################## $CurrentScriptDirectory = $PSCommandPath.Substring(0,$PSCommandPath.LastIndexOf(“\”)) Set-Location $CurrentScriptDirectory     #Thanks to http://gallery.technet.microsoft.com/scriptcenter/63fd1c0d-da57-4fb4-9645-ea52fc4f1dfb     $IsAdmin = ( ::GetCurrent()).IsInRole( “Administrator”)          if …

Azure Service Manager Account & Subscription Cache

If you are using the Azure Service Manager Module you will notice that the cmdlet’s such as Add-AzureAccount and Login-AzureAsAccount cache the subscriptions that the user has access to (the user which is specified in the credentials used to authenticate). Where is this cache maintained locally on the client? For Windows desktops it is in the users %appdata% directory.  For …

Quick Launch to the Microsoft Office 365 and Azure Management Portals

If you often use both the Microsoft Office 365 and Azure Management Portals, and use them with several different tenants, credentials, and subscriptions, it helps to quickly launch a web browser in private mode to those two portals.  The private mode segregates the credentials across tenants and subscriptions. I nifty time saver I use it to create two Windows Desktop …

Azure PowerShell Tips and Tricks

Here are a few key references and a few tips and tricks. Key Resources Name Description Link AzureRM PowerShell Documentation The documentation root for AzureRM.  Note the Version selector to get documentation on previous versions. https://docs.microsoft.com/en-us/powershell/azure/overview?view=azurermps-4.0.0 AzureRM.Profile Documentation Authenticating is the first step.  This is the reference to the AzureRM.Profile module which contains the cmdlet’s to do that.  https://docs.microsoft.com/en-us/powershell/module/azurerm.profile/?view=azurermps-4.0.0 AzureRM …

Azure AD PowerShell Modules

There have been several Windows Azure Active Directory Modules.  Here is a quick reference. What Versions Exist? Microsoft’s evolution and naming of the modules has caused some confusion: V1.  The initial PowerShell module for Azure AD  is named “MSOnline” and was also known as the Office 365 PowerShell module  https://docs.microsoft.com/en-us/powershell/module/msonline/?view=azureadps-1.0 V2.  The new version (V2) is called Azure AD PowerShell …

How to Clean Up PowerShell Script Variables without Restarting PowerShell ISE

Many times while authoring PowerShell scripts, the expected output will be incorrect because PowerShell ISE does not automatically cleanup it’s variable between manual runs of a script.  In my experience this poses two practical issue which lead to incorrect script results: 1) If the variable is not explicitly re-initialized in the script (very common practice), the script will be initialized …

Determining whether a User account is Sourced from On-Premises or Azure AD

In hybrid Office 365 deployments (either Exchange Online, Skype for Business Online, or SharePoint Online), often you need to know whether a particular user account is sourced (e.g. created) from on-premises AD, or in the cloud (created in Azure AD). This can be see in the Office 365 Portal (under Admin centers | Azure AD).  In the classic Azure AD …

Microsoft Security Day

Microsoft Canada is holding a Security Day (#MSFTSecure) on Tuesday, March 28th, 2017. They have highlighted some fantastic resources to educate and spread awareness of security in Azure and other Microsoft technologies: Find out why Comprehensive security comes standard  #MSFTSecure #MSpartner Find out why Windows Defender is Malware’s worst enemy #MSFTSecure Get more security features, safer authentication & ongoing updates …

A Clever Method to Call .NET from PowerShell

I came across a very interesting PowerShell technique today courtesy of Guy Bachar’s TechNet Gallery Script Exchange Online Audit Log Report (HTML Format). This PowerShell script contains .NET code which calls the local Windows Credential Manager.  Pheww!  Could come in handy. …. . ###################################################################### # API to load credential from generic credential store ###################################################################### $CredManager = @” using System; using …