Introduction
In a recent blog post, we walked through paging for Microsoft 365 and how to use it. The question is, how do you know when paging is an available option? We could potentially look at the parameters for each cmdlet, one by one, but that would be a tedious process. Could we instead use PowerShell to parse each cmdlet and find those parameters? Simple answer is yes. So let’s walk through the process and see the results.
Finding the Answers
How can we get the parameters for a cmdlet? Well, we could use Get-Help and find some way to parse them out with PowerShell, which seems a bit over complicated. What if we could find a way to list just the parameters of a cmdlet? Well we can. See this article below:
https://sid-500.com/2017/07/25/powershell-cmdlets-list-all-availabe-parameters-without-using-the-help/
From this article we see this one-liner:
(Get-Command Get-ChildItem).Parameters
It does provide what we need, but there is a bit of extra noise involved:
How do we handle the Key value? Looking into this with a bit of research, we see this article has a good methodology:
https://www.oreilly.com/library/view/mastering-windows-powershell/9781787126305/f98a875f-4fef-4218-8795-cedecca047e9.xhtml
Combining these two, with some extra code, we can now pull put any parameter with the word page or pagesize in it.
Script Code
In this example, we explore the paging parameter available in the Exchange Online
# Retrieve cmdlets with a source of 'tmpEXO_zhdgfxgn.qjz' - currently for ExO cmdlets $Commands = Get-Command | Where Source -eq tmpEXO_zhdgfxgn.qjz # Go through each cmdlet to find the correct parameters Foreach ($Command in $Commands) { $Check = $Null $Test = (Get-Command $Command).Parameters $Check = $Test.Keys -like '*page*' If ($Check -ne $Null) { $Check2 = $Test.Keys -like '*pagesize*' If ($Check2 -ne $Null) { $Parameters = $Check -join ',' Write-Host "$Command" -ForegroundColor Green -NoNewLine Write-Host ": $Parameters" -ForegroundColor White } } }
Conclusion
This same set of code could be used against other PowerShell modules – Security and Compliance Center, Microsoft Teams and more. Please let some feedback if you think this was a useful bit of code.
———————————————————————————————————–
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: