Powershell Debugging using PowerShell ISE

Background

Having a need to see why a Powershell code is not coming to the end I wanted.

Usual

Usually I will tinker with it by adding a bunch of Write-Host code, but today wanted to be a little lazy and also I can be more trusting as it is code I have already done enough with it already.

PowerShell ISE

Introduction

That is where Windows PowerShell Integrated Scripting Environment ( ISE ) comes in.

Install

If you are unable to run “Powershell ISE” through the start menu, please enable it.

Note, you need to be running at least MS Windows 7 or MS Windows 2008.

PowershellISE_launch_20180620_0552PM

Code

Powershell

Link

Import-Module ServerManager
Add-WindowsFeature PowerShell-ISE

GUI

Using Server Explorer
Link

  1. Open the Server Explorer
  2. Navigate to the Features Node
  3. Right-click on Features node, selectAdd Features
  4. You will get Add Features wizard with list of features provided with checkboxes.
  5. Check the “Windows PowerShell Integrated Scripting Environment (ISE)”
  6. Click on Next button
  7. Click on Install button.

Use

Start

Start Powershell ISE

Load Powershell File

Powershell_load_20180620_0556PM

Set Breakpoints

Review code and on each line that you want to break on, please press F9 or right click and select break-point from the drop-down menu.

powershellISE_Setbreakpoint_20180620_0558PM

 

Command Window

Watch Variable

Via Command Window, enter variable name and press enter command

watchVariable_20180620_0603PM

Set Variable

Program Argument

Via Command Window, set variable

Script

Sample

$PSDefaultParameterValues.add("Engine.ps1:CurrentLoginName","LAB\dadeniji")

Image

currentLoginName_20180620_0607PM.jpg

 

 

 

Windows 10 – Marketing Name via PowerShell

Background

Reading through MSFT’s documentation on installing the “Linux Subsystem on MS Windows” brought to light the need to familiarize oneself with the various marketing moniker for each Released build of MS Windows 10.

Literature

Here is the specific document…

Install the Windows Subsystem for Linux
Link

And, here are the specific texts that juiced my appetite:

Image

Falls Creator Update

linuxPlatform_FallCreatorUpdate_20180613_1150AM.png

Anniversary Update and Creators Update

linuxPlatform_AnniversaryAndCreatorsUpdate_20180613_1152AM.png

Explanation

So the question is which MS Windows 10 Update am I running ….

Referenced Work

Thanks goodness there are various credible sources doing the heavy work of lining up MSFT’s version #, Marketing Version, and Build Number  low & high bars.

Here are the sources we used for this post:

  1. Microsoft
    • Windows 10
      • Windows 10 release information
        Link
  2.  Wikipedia
    • Windows 10 version history
      Link
  3. PureInfotech
    • Mauro Huculak
      • Windows Update History information helps you know exactly what’s the latest version of Windows 10 available.
        Link

Image

Wikipedia – Windows 10 – Version History

wikipedia_Windows10VersionHistory_20170613_1225PM

Code

Text file

Text file – UpdateList.txt

Outline

  1. Here is our file’s content
    • Version
    • Marketing
    • Build Number – Min
    • Build Number – Max

1809, Windows 10 version 1809 (Late 2018), 17686.00, 17686.00
1803, Windows 10 version 1803 (April 2018 Update) history, 17133.73, 17134.83
1709, Windows 10 version 1709 (Fall Creators Update) history, 16299.15, 16299.461
1703, Windows 10 version 1703 (Creators Update) history, 15063.11, 15063.1112
1607, Windows 10 version 1607 (Anniversary Update) history, 14393, 14393.2189
1511, Windows 10 version 1511 (November Update) history, 10586.104, 10586.1176
1507, Windows 10 version 1507 (Initial Release) history, 10240.16683, 10240.17831

PowerShell

PowerShell – getWindows10MarketingName.ps1

Outline

  1. Read flat file ( updateList.txt)
  2. Get MS Windows Version via calling [Environment]::OSVersion
    • Build Number
  3. Get MS Windows by issuing “Get-WmiObject Win32_OperatingSystem
    • Returns
      • Caption
      • OSArchitecture
  4. Registry Access – Get-ItemProperty
    • Argument :- HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion
    • Returns
      • ProductName
      • ReleaseID
      • CurrentBuildNumber
      • CompositionEditionID
  5. Iterate read file
    • Condition to indicate match
      • If ReleaseID from registry Path HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion matches read record
      • If Build Number falls into range of read record
    • Save Pointer
  6. If Pointer Saved
    • Display OS Version from table

Preparatory

Registry
Registry – HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion

registry_20180614_0700AM.png

 

Actual Code


Set-StrictMode -Version 1
  

[boolean]$debug=$false;
[string] $objOSVerNumberAsString = $null;
[double] $versionNumberMinAsNumber = 0;
[double] $versionNumberMaxAsNumber = 0;
[boolean] $bConverted = $false;
[string] $strLog = $null;
#[string] $CHAR_EMPTY='';
#PowerTip: Create Empty String with PowerShell
[string] $CHAR_EMPTY=[string]::Empty;

[string] $productName =$null;
[string] $releaseID =$null;
[string] $currentBuild =$null
[string] $edition =$null;

[string] $releaseIDInList = $null;

$debug=$false;
#$debug=$true;

$updateListFilename = 'updateList.txt';

#read file updateList.txt
$updateList = Get-Content $updateListFilename;

#Display Update List
#$updateList;

#Get OS version [Environment]::OSVersion
$objOSVer =[Environment]::OSVersion;

#Display OS version
Write-Host('OS Version');
Write-Host('----------');
Write-Host($objOSVer);


$objOSVerPlatform = $objOSVer.Platform;
$objOSVerServicePack = $objOSVer.ServicePack;
$objOSVerNumber = $objOSVer.Version;
$objOSVerString = $objOSVer.VersionString;


$objOSVerNumberAsString = [system.String]::Join($CHAR_EMPTY, $objOSVerNumber);


$objOSVerNumber0 = $objOSVerNumberAsString.split('.')[0];
$objOSVerNumber1 = $objOSVerNumberAsString.split('.')[1];
$objOSVerNumber2 = $objOSVerNumberAsString.split('.')[2];
$objOSVerNumber3 = $objOSVerNumberAsString.split('.')[3];


$objOSVerNumberBase = $objOSVerNumber0;
$objOSVerNumberSP = $objOSVerNumber1;
$objOSVerNumberBuild = $objOSVerNumber2;
$objOSVerNumberMinor = $objOSVerNumber3;

if ( $debug)
{

    Write-Host('');

    Write-Host('OS Version ( broken into pieces)');
    Write-Host('--------------------------------')  

    Write-Host('OSVersionPlatform      :- {0}' -f $objOSVerPlatform);
    Write-Host('OSVersionServicePack   :- {0}' -f $objOSVerServicePack);
    Write-Host('OSVersionNumberAsArray :- {0}' -f $objOSVerNumber);
    Write-Host('objOSVerNumberAsString :- {0}' -f $objOSVerNumberAsString);
    Write-Host('OSVersionString        :- {0}' -f $objOSVerString);

    Write-Host('objOSVerNumberSP       :- {0}' -f $objOSVerNumberSP);
    Write-Host('objOSVerNumberBuild    :- {0}' -f $objOSVerNumberBuild);

    Write-Host('');
}

  

$objWMIOS = (Get-WmiObject Win32_OperatingSystem);

if ($objWMIOS -ne $null)
{
	Write-Host('');

    Write-Host("WMI - Win32_OperatingSystem");
	#$objWMIOS;

	$WMIOSCaption = $objWMIOS.caption;
	$WMIOSArchitecture = $objWMIOS.OSArchitecture;

	$strLog = "`t WMI OS - Caption        :- {0}" -f $WMIOSCaption;
	Write-Host $strLog;

	$strLog = "`t WMI OS - OSArchitecture :- {0}" -f $WMIOSArchitecture;
	Write-Host $strLog;	

	Write-Host('');
}


$strRegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion";
$objRegWinOS = (Get-ItemProperty $strRegPath);

if ($objRegWinOS -ne $null)
{

	Write-Host('');
    Write-Host("Registry Path $strRegPath");
	#$objRegWinOS;

	$productName = $objRegWinOS.ProductName;
	$releaseID = $objRegWinOS.ReleaseID;
	$currentBuild = $objRegWinOS.CurrentBuildNumber;
	$edition = $objRegWinOS.CompositionEditionID;

	$strLog = "`t WinOS Registry - productName :- {0}"`
				-f $productName;
	Write-Host $strLog;

	$strLog = "`t WinOS Registry - ReleaseID :- {0}" `
				-f $releaseID;
	Write-Host $strLog;

	$strLog = "`t WinOS Registry - Current Build :- {0}" `
				-f $currentBuild;
	Write-Host $strLog;

	$strLog = "`t WinOS Registry - Edition :- {0}" `
				-f $edition;
	Write-Host $strLog;

	Write-Host('');
}


$i = 0;
$entry = $null;
$entrySaved = $null;


$iNumberofUpdates = $updateList.Length;

Write-Host '';
Write-Host 'Iterating Build List looking to match OS Build Number ... ';
Write-Host '';


foreach ( $entry in $updateList )
{

  $releaseIDInList =$entry.split(',')[0];
  $update=$entry.split(',')[1];
  $versionNumberMin=$entry.split(',')[2];
  $versionNumberMax=$entry.split(',')[3];

  
  $bConverted = [double]::TryParse(`
                      $versionNumberMin`
                    , [ref] $versionNumberMinAsNumber);

  $bConverted = [double]::TryParse(`
                    $versionNumberMax`
                      , [ref] $versionNumberMaxAsNumber);                               

  if ($debug)
  {

    Write-Host('Build {0} -f $objOSVerNumberBuild ');

    $strLog = 'versionNumberMin {0}' `
				-f $versionNumberMinAsNumber;
	Write-Host($strLog);

    $strLog = 'versionNumberMax {0}' `
				-f $versionNumberMaxAsNumber;
	Write-Host($strLog);	

  }     

  if (
			( $releaseID -eq $releaseIDInList) `
		-or `
			( `
				     ( $objOSVerNumberBuild -ge $versionNumberMinAsNumber) `
				-and ( $objOSVerNumberBuild -le $versionNumberMaxAsNumber) `
			)
	 )
    {
        # save entry
        $entrySaved = $entry;

        break;
    }

  $i = $i + 1;  

} # foreach ( $entry in $updateList )   


if ($entrySaved -ne $null)
{

    # Get fields
    $matchVersion = $entrySaved.split(',')[0];
    $matchMarketing = $entrySaved.split(',')[1];
    $matchBuildMin = $entrySaved.split(',')[2];
    $matchBuildMax = $entrySaved.split(',')[3];

    Write-Host("Version Matched");

    Write-Host("`t Version   :-  $matchVersion");

    $strLog = "`t Build     :-  {0} through {1}" `
                -f $matchBuildMin.Trim() `
				 , $matchBuildMax.Trim();

    Write-Host($strLog);

    Write-Host("`t Marketing :- $matchMarketing");

}
else
{

    $strLog = 'Version Number ({0}) not found!' -f `
                $objOSVerNumberBuild;

    Write-Host($strLog);            

}

Invoke

Syntax

powershell -file ./getWindows10MarketingName.ps1

Output

getMSWindows10UpdateName_Work_20180613_0742PM.png

Source Code Control

GitHub

DanielAdeniji/WinOSMarketingNameUsingPS
Link

Listening

Listening to the song I first heard during yesterday’s parade:

Drake – Nice for What
Link

Lyrics

You got to be nice for what to these …..

Windows 10 – Installing Linux SubSystem

Background

Availing Linux on MS Windows 10.

Here is the guide that we will be using:

Windows 10 Installation Guide
Install the Windows Subsystem for Linux
Link

Outline

  1. Enable Windows Feature
    • Microsoft Windows Subsystem Linux
  2. Review OS Version
    • Issue SystemInfo and get OS Version and Build Number
  3. Choose Install Location, based on Build Number
    • If Build Number > 16215
      • We can install from Windows Store
    • Else
      • Enable Windows Developer Mode
      • Start Bash or use “lxrun /install
  4. Register Product
  5. Create Linux User
  6. Set root user’s password

 

Install Steps

Enable Windows Optional Features

Microsoft-Windows-Subsystem-Linux

Code

powershell -C "Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux"

System Info

Code


powershell -C "systeminfo | Select-String 'OS' "

Output

version_20180610_0902PM

Explanation

As our Build Number ( 17134 ) is greater than 16215, we can install via “Microsoft Store“.

Microsoft Store

Visit Microsoft Store and search for Linux.

https://www.microsoft.com/en-us/search/result.aspx?q=linux

Here is the result of that search:

MicrosoftStore_Linux.PNG

 

SUSE Linux Enterprise Server 12

We chose to go with SE Linux.

SUSE Linux Enterprise Server 12 – Get

SUSELinuxEnterprise_20180610_0905PM.PNG

Use across your devices

UseAcrossYourDevices_20180610_0906PM.PNG

Add your Microsoft account to Microsoft Store

AddYourMicrosoftAccountToMicrosoftStore_20180610_0921PM [brushedup].PNG

Enter Password

AddYourMicrosoftAccountToMicrosoftStore_EnterPassword_20180610_0923PM.PNG

Installing

Installing_20180610_0911PM

SUSE Linux Enterprise Server 12 – Registration +User

registration_20180610_0926PM.PNG

SUSE Linux Enterprise Server 12 – Registration +User +Password

registrationUserAndPassword_20180610_0927PM.PNG

Validation

Bash

uname

Get Linux Version

Code


uname -r

Output

bash_uname_20180610_0938PM

List Users

Code


cat /etc/passwd

Output

security_users_20180610_0947PM.PNG

References

  1. Microsoft
    • Install the Windows Subsystem for Linux
      • Install the Windows Subsystem for Linux
        Link
    • Rich Turner
      • Bash on Ubuntu on Windows – Download Now!
        Link

SQL Server & PowerShell – Get Memory Utilization

Background

Earlier today I found myself trying to better understand a system.

As part of my quick read-up, I found a one line code that shows how to read memory utilization via Powershell.

Code

Overview

Here is that one line code in far too many lines.

Powershell


Set-StrictMode -Version Latest;
Import-Module SQLPS -DisableNameChecking

function displayPath($path)
{
	[object] $objGI = $null;
	[int] $physicalMemoryUsageInKB = 0;
	[int] $physicalMemoryUsageInMB = 0;

	$objGI = (gi $path) 
	
	#Get Data
	$displayName = $objGI.DisplayName;
	$physicalMemoryUsageInKB = $objGI.PhysicalMemoryUsageInKB;
	$physicalMemoryUsageInMB = $objGI.PhysicalMemoryUsageInKB / 1024;
	
	#Display Data       
	$strLog = "`tPath {0}" -f $path;        
	Write-Host $strLog
	
	$strLog = "`tInstance {0}" -f $displayName;     
	Write-Host $strLog
	
	$strLog = "`tPhysical Memory (KB) {0}" -f $physicalMemoryUsageInKB;     
	Write-Host $strLog
	
	$strLog = "`tPhysical Memory (MB) {0}" -f $physicalMemoryUsageInMB;     
	Write-Host $strLog      
	
	Write-Host
        
}

[string] $typeSQLEngine = "SqlServer";
[string] $defaultInstance = "MSSQLServer";
[string] $machineName = $null;
[int]    $iNamedInstanceStartingPos = 6;

# Get machine name
$machineName = $env:computername


#Get a managed computer instance  
$mc = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer  

#List out all sql server instances running on this machine  
foreach ($item in $mc.Services)
{

	if ($item.Type -eq $typeSQLEngine)
	{
		
		if ($item.Name -eq $defaultInstance)
		{
			$instanceName = "DEFAULT";
		}
		else
		{
		
		    $instanceNameLen = ($item.Name).length - $iNamedInstanceStartingPos;
			
			$instanceName = ($item.Name).Substring( `
													  $iNamedInstanceStartingPos `
													, $instanceNameLen `
												  );
			
		}
		
		$path = "SQLSERVER:\SQL\" + $machineName + "\" + $instanceName;
		
		displayPath $path
					
	} # if ($item.Type -eq $typeSQLEngine)
	
} 

Output

 

Source Code Control

GitHub

DanielAdeniji/SQLServerPS

Link

SQL Server – Dynamic SQL Queries – Duplicate Plans ?

Background

In the last couple of weeks we have taken a sure aim at some of our dynamic queries.

This morning came in and started reviewing our cached plans and noticed that we might have duplicates.

 

Cached Plans

Image

Here is a slimmed down version of our cached Plans

Explanation

I was wondering why it seems I have duplicate entries filtering on timePeriod, stateLimit, and Phone.

The first entry has 2040 hits and the other 134 matches.

 

Comparison

SQL Server Management Studio ( SSMS )

I tried to compare the plans using SQL Server Management Studio v2017, but nothing jumped at me.

 

Dynamic Management Views

sys.dm_exec_plan_attributes

I also looked at the normal causes such as:

  1. userid
    • attribute user_id
  2. Set Options
    • Attribute set_options
      • Quoted Identifier
      • Ansi Nulls

 

Text File Comparison

I then saved the query plans into text files and used an online text comparison tool.

DiffNow

DiffNow is here.

From the few differences between the files, here is why my eyes finally rested.

Image

 

Explanation

  1. Saw that @stateLimit only appears in the second plan

 

In Code

Output

Using XQuery was able to confirm that different queries is indeed attributable to slight variation in filtering columns.

Parameter List

Sample 1

 

Sample 2

 

Take away

Thankfully considering text file comparison got me closer to identifying the causation of the “duplicate” plans.

PowerShell – Environment Customization – Prompt

Background

By default, when one initiates Powershell, the environment prompt takes upon the current folder.

Default Prompt

Customization

Outline

  1. Determine the name of our Powershell Profile file
  2. Edit existing file or create a new one
    • Add function called prompt

Get Profile file

Syntax

powershell -Command "Write-Host('Profile file is {0}', $profile);"

Output

Textual


C:\Users\dadeniji\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

 

Edit Profile file

Sample


function prompt
{
	[string] $prompt;
	
	$prompt = ">";
	
	return($prompt);
	
}

Validate

In a new command shell, launch powershell…

And, irrespective of our current folder, we will be greeted with “PS>”.

References

  1. Microsoft
    • Microsoft Technet
      • Scripting Guy
        • Change the Powershell Prompt
          Link
  2. Robert Sheldon
    • ITProToday
      • PowerShell Basics: Console Configuration
        How to customize the PowerShell console
        Link

Powershell Modules – AzureAD – “Get AD Policy”

Background

Using the “AzureAD” Powershell module, let us review how Azure-AD User Policy is configured.

PowerShell Modules

Currently, there are two versions of the Azure AD Powershell module.

  1. AzureAD ( Release Module )
  2. AzureADPreview ( Preview Module )

The functionality we need is only available in the Preview Module.

Installation

Review

Let us review the version we have installed.

Syntax


powershell -Command "Get-Module -ListAvailable" -Name "*Azure*"

Output

AzureAD

AzureADPreview

Explanation

Please review the following Columns

  1. Module
    • AzureAD ( released version )
    • AzureADPreview ( yet to be released )

Upgrade

Let us upgrade our install.

Syntax


Powershell -Command "UnInstall-Module AzureAD"
Powershell -Command "Install-Module AzureADPreview"

Code

Outline

  1. To connect to our “Tenants Domain“, Issue “Connect-AzureAD
  2. To get AzureAD policies, call Get-AzureADPolicy
    • Get the returned object type by issuing GetType().Fullname

 

API

Get-AzureADPolicy

Let us make have a proper insight on how to invoke the Get-AzureADPolicy.

Get-Help

Syntax

Get-Help Get-AzureADPolicy

Output

Explanation

We can see that Get-AzureADPolicy really accepts only a singular argument.

It is an optional one, Id.

 

Get-Help -detailed

Syntax

Get-Help Get-AzureADPolicy -detailed

Output

Explanation

When we pass in “-detailed” we see that the ID is the Policy ID.

Get-Help -example

Syntax

Get-Help Get-AzureADPolicy -examples

Output

Examples

Unfortunately, there is nothing here per examples.

Actual Code


Set-StrictMode -Version Latest;

[string]$CHAR_NEWLINE ="`r`n";

function listObjectProperties($object)
{
 
    [int] $iPropertyIndex = 0;
 
    #prepare formatting
    $strFormat = "{0}) Name :- {1} - Value :- {2}"
 
    #Iterate Object Properties
    Foreach ($objProperty in $object)
    {
 
       # increment property counter
       $iPropertyIndex = $iPropertyIndex + 1;
 
       $objPropertyName = $objProperty.Name;
 
       #place variable name in single quotes to ensure that
       #PowerShell does not evaluate\substite value
       $objPropertyNameFull = '$object' + '.' + $objPropertyName

	   <# # dadeniji 2018-01-22 10:30 AM #commented out and replaced with "$($objProperty.Value) # prepare to use variable substitution # Invoke-Expression # http://technet.microsoft.com/en-us/library/dd347550.aspx # $objPropertyValue = invoke-expression $objPropertyNameFull; #>	
	   
	   #$objPropertyValue = invoke-expression $objPropertyNameFull;
	   
	   $objPropertyValue = "$($objProperty.Value)"
 
       #format data
       $strLog = [String]::Format(
                                         $strFormat
                                       , $iPropertyIndex
                                       , $objPropertyName
                                       , $objPropertyValue
                                  );
 
       # display data
       $strLog;
 
     }
 
}

try
{

	$objCredential = Get-Credential -ErrorAction SilentlyContinue

}
catch
{

     $strLog = "get-Credential failed!";
	 
	 $strLog = $strLog + $CHAR_NEWLINE + $_.Exception.Message
	 
	 Write-Host $strLog -ForegroundColor red 
     
	 return

}
	
if (!$objCredential)
{
     
	 $strLog = "get-Credential failed!";

	 Write-Host $strLog -ForegroundColor red;
	 
     return
	 
}

#Connect to Azure AD
try
{

	$connect = Connect-AzureAD  -Credential $objCredential -ErrorAction SilentlyContinue
}
catch
{

     $strLog = "Connect-AzureAD failed!";
	 
	 $strLog = $strLog + $CHAR_NEWLINE + $_.Exception.Message
	 
	 Write-Host $strLog -ForegroundColor red 
     
	 return

}

if (!$connect)
{

     $strLog = "Connect-AzureAD failed!";
	 
	 Write-Host $strLog -ForegroundColor red 
     
	 return

 }

 
#Get-AzureADPolicy
try
{

	 
	# get list of AD Policy
	#$objListofADPolicy = Get-AzureADPolicy  -ErrorAction SilentlyContinue
	$objListofADPolicy = Get-AzureADPolicy

}
catch
{

     $strLog = "Get-AzureADPolicy failed!";
	 
	 $strLog = $strLog + $CHAR_NEWLINE + $_.Exception.Message
	 
	 Write-Host $strLog -ForegroundColor red 
     
	 return

}

# if List is empty, then say so
if (!$objListofADPolicy)
{
	 
     $strLog = "Get-AzureADPolicy failed!";
 
	 Write-Host $strLog -ForegroundColor red 
     
	 return
}
 
# Keith Hill - Get Type name
# the-typename-and-inheritance-chain/
# http://rkeithhill.wordpress.com/2007/10/28/powershell-quicktip-using-pstypenames-to-see-# 
$strLog = "Type name is " + $objListofADPolicy.GetType().Fullname;
$strLog
 
# Get top item in list
$objADPolicy = $objListofADPolicy | Select-Object -first 1

# if List is empty, then say so
if (!objADPolicy)
{

     $strLog = "Object (objADPolicy) is null (empty)";
	 
	 Write-Host $strLog -ForegroundColor red 
 
     return

 }
 
#Show all of Object's properties 
#https://www.codykonior.com/2013/03/26/powershell-how-to-show-all-of-an-objects-properties-and-values/
$objADPolicyPropList = $objADPolicy | Select-Object -Property *

if (!$objADPolicyPropList)
{
	 
     $strLog = "Object has no properties";
	 
	 Write-Host $strLog -ForegroundColor red 

	 return
}

$objADPolicyPropList


# get Object Properties
#   By calling PsObject.Properties
$objADPolicyProps = $objADPolicy.PsObject.Properties;

#list properties
listObjectProperties($objADPolicyProps);

Source Code

GitHub

DanielAdeniji/Office365AzureADPowerShell
Link

Specifically Office365AzureADPolicy.ps1.

Summary

There are so many ways to go wrong on this one.

Inclusive are:

  1. Installation
    • Having the right PowerShell Module
      • AzureAD or AzureADPreview
  2. Security
    • Having enough security on your Tenant Account
      • If one does not
        • Errors not returned when one issues Get-AzureADPolicy
        • The only indicator is that null is returned

References

  1. Microsoft
    • Microsoft Azure
      • Azure / Azure PowerShell
        • Azure Active Directory PowerShell for Graph
          Link
        • Get-AzureADPolicy
          Link
    • Microsoft – Docs
      • Office 365 Enterprise > Manage Office 365 with Office 365 PowerShell > Getting started with Office 365 PowerShell > Connect to Office 365 PowerShell
        • Connect to Office 365 PowerShell
          Link
    • Tech Community
      • Home > Azure Active Directory > Azure Active Directory
        • Azure AD PowerShell v2 cmdlets not working, e.g. Get-AzureADPolicy
          Link