Exercise - Format your output
In this unit, you use Azure Cloud Shell to format your PowerShell output. Azure Cloud Shell is a shell that you can access through the Azure portal. You don't have to install anything on your PC or laptop to use it.
Note
This exercise is optional. If you want to complete this exercise, you'll need to create an Azure subscription before you begin. If you don't have an Azure account or you don't want to create one at this time, you can read through the instructions so you understand the information that's being presented.
Compare formatting approaches
Different output formats make sense for different scenarios. For example, depending on the type of data that you want to display, a table might make more sense than a list.
Some cmdlets use a certain type of formatting by default. You can override the default formatting by using a formatting cmdlet.
Type
pwshin a terminal window to start a PowerShell session:pwshIn your PowerShell shell, run the
Get-Membercommand:"a string" | Get-MemberThe output is a table that lists all the members. Here are the first few lines of the output:
Name MemberType Definition ---- ---------- ---------- Clone Method System.Object Clone(), System.Object ICloneable.Clone() CompareTo Method int CompareTo(System.Object value), int CompareTo(string strB), int IComparable.CompareTo(…Next, you override the default formatting by using the
Format-Listcmdlet.Run the
Format-Listcommand, as shown here:"a string" | Get-Member | Format-ListThe resulting output is different from the preceding output. The first few lines now appear as a list, as shown here:
TypeName : System.String Name : Clone MemberType : Method Definition : System.Object Clone(), System.Object ICloneable.Clone() TypeName : System.String Name : CompareTo MemberType : Method Definition : int CompareTo(System.Object value), int CompareTo(string strB), int IComparable.CompareTo(System.Object obj), int IComparable[string].CompareTo(string other)