Introduction
As someone that spends a lot of time working with PowerShell, I have a tendency to review the help for a cmdlet either with Get-Help or checking on Microsoft’s Learn pages. Sometimes I see things that trigger my curiosity and this has happened recently when I was reviewing cmdlets for one of Microsoft Graph’s submodules on Identity Management. While reviewing the help for a few cmdlets, I noticed that the Synopsis for two or more cmdlets was the exact same which is curious as the cmdlets would appear to perform similar operations but with a different methodology. With this little nugget in mind, I decided to compare the synopsis of each of the cmdlets in the ‘Microsoft.Graph.Identity.DirectoryManagement’ module to see which were similar or not.
Where to Start
To make this all work we need to come up with a plan, a set of steps to work through, and then write up PowerShell code to make the analysis. These are the steps I came up with:
- Retrieve all cmdlets for the PowerShell Module
- Retrieve the Synopsis for the cmdlet and store it with the cmdlet name in an array
- Compare each cmdlet’s synopsis for matches
- Remove any duplicate data and distill the results, sorted by synopsis and then sort by cmdlet name
Retrieve all cmdlets for the PowerShell Module
$Module = 'Microsoft.Graph.Identity.DirectoryManagement' $SynopsisArray = @() $Cmdlets = Get-Command | Where Source -eq $Module
Clear out Graph Cmdlets [EXTRA]
As noted in a previous article, there is a weird bug in Graph PowerShell and Get-Help. See this article for reference.
Try { $Test = Get-Help $Cmdlets[0] -ErrorAction Stop } Catch { $HelpError = $True } $Cmdlets = Get-Command | Where Source -eq $Module
Retrieve the Synopsis for the cmdlet and store it with the cmdlet name in an array
$SynopsisArray += "Name,Synopsis" Foreach ($Cmdlet in $Cmdlets) { # $Cmdlet.Name $TempFile = "$Cmdlet"+'-synopsis.txt' (Get-Help $Cmdlet).Synopsis | Out-File -FilePath $TempFile $Synopsis = (Get-Content $TempFile) If ($Synopsis.Count -gt 1) { $Synopsis = (Get-Content $TempFile)[0] } $Name = $Cmdlet.Name $Phrase = "$Name/$Synopsis" $SynopsisArray += ($Phrase) Del $TempFile } $SynopsisArray | Out-File -FilePath 'SynopsisArray.txt'
Compare each cmdlet’s synopsis for matches
$CSV = Import-CSV .\SynopsisArray.txt -Delimiter '/' $Matches = $Null $Matches = @() $Matches += "Name/Synopsis" Foreach ($Line in $CSV) { $StringCheck = $Line.Synopsis $Cmdlet = $Line.Name Foreach ($Line2 in $CSV) { $Synopsis = $Line2.Synopsis If ($Synopsis -eq $StringCheck) { If ($Line -ne $Line2) { $CmdletToAdd = $Line2.Name $CmdletString = "*"+$CmdletToAdd+"*" $AllSynopsis += "*"+$Synopsis+"*" If ($AllSynopsis -NotLike $StringCheck) { $Matches += $Line } } } } }
Remove any duplicate data and distill the results, sorted by synopsis and then sort by cmdlet name
$Matches | Sort Name -Unique | Sort Synopsis,Name | Out-File -FilePath DuplicateSynopsis.txt
Sample Results
This is the output from the script run:
Conclusion
While we had a chance to use one SubModule of the Microsoft Graph PowerShell Module, we could expand the analysis to ALL submodules and see that there are a lot of duplicate synopsis’ in each module. This exercise did concentrate on a particular scenario, some of the concepts that can be reused with other scenarios are different delimiter usages: ‘/’ in this case instead of ‘,’ in case there were commands in either field. We also used the Sort option for not one, but two different columns in
Comments? Questions?
Feel free to leave your Comments below! Learn to more efficiently utilize PowerShell to manage Exchange Server, Exchange Online, Microsoft Defender for Office or Microsoft Purview Compliance portals by picking up frequently updated eBooks: