{"id":53013,"date":"2009-07-06T03:01:00","date_gmt":"2009-07-06T03:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/07\/06\/hey-scripting-guy-how-can-i-simply-have-windows-powershell-display-information-on-the-screen\/"},"modified":"2009-07-06T03:01:00","modified_gmt":"2009-07-06T03:01:00","slug":"hey-scripting-guy-how-can-i-simply-have-windows-powershell-display-information-on-the-screen","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-simply-have-windows-powershell-display-information-on-the-screen\/","title":{"rendered":"Hey, Scripting Guy! How Can I Simply Have Windows PowerShell Display Information on the Screen?"},"content":{"rendered":"<h2><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> Hey, Scripting Guy! <span><span>I am not into all those fancy scripts you seem to write. I am just a basic, everyday network administrator, and I simply need to use scripts to make my job easier. Because of this, I am not interested in displaying progress bars, writing stuff to Excel or Word or even PowerPoint. I am interested simply in having my Windows PowerShell script display information on the screen. What is the best way to do this?<\/span><\/span><\/p>\n<p><font color=\"#333333\">&#8211; CO<\/font><\/p>\n<p><font color=\"#333333\"><img decoding=\"async\" border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><\/font> <\/p>\n<p>Hi CO,<\/p>\n<p><span>At times it seems like only yesterday, but when I started out in the field of IT, I also was a basic, everyday network administrator. The days were never boring because the problems were never the same. I would show up in my office, and there would be a message from a user stating they could not get logged on to the network; while I was resetting their password, I would check my e-mail and find out that someone else was having problems creating a macro in Office Excel. As I checked my project board, I saw that I needed to get a new network drop installed in a remote office. I also had to teach a class in the afternoon on basic Office Outlook for a dozen new users. Yep, being a basic, everyday network administrator was a lot of fun. I never got bored.<\/span> <\/p>\n<p><span>The one thing I never had was free time. Back then I used to drink coffee, but I don&#8217;t think I ever actually finished a cup of coffee before it was cold. I actually got to where I could drink cold coffee without cringing and shuddering. Because I was so busy running from problem to problem, I seldom wrote scripts. When I did write a script, it would display information on the screen because I always ran the scripts in an interactive fashion. Years later, after I began working at Microsoft, my good friend Jason and I went to <a href=\"http:\/\/en.wikipedia.org\/wiki\/Hong_Kong\"><font face=\"Segoe\">Hong Kong<\/font><\/a> where I learned a new appreciation for interactive displays. Here is a good picture of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Hong_Kong_Harbor\"><font face=\"Segoe\">Victoria Harbor<\/font><\/a> I took from a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Hydrofoil\"><font face=\"Segoe\">hydrofoil<\/font><\/a> on my way to <a href=\"http:\/\/en.wikipedia.org\/wiki\/Macau\"><font face=\"Segoe\">Macau<\/font><\/a>.<\/span> <\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" title=\"Image of Victoria Harbor\" alt=\"Image of Victoria Harbor\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/july\/hey0706\/hsg-07-06-09-01.jpg\" width=\"600\" height=\"400\"><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">CO, when displaying information on the screen, the most important thing to remember is that it is easy. In many cases, you do not have to do anything more complicated than to run the cmdlet. When you do, you are automatically rewarded with nicely formatted output that is displayed on the screen: <\/p>\n<p class=\"Num-Caption\"><img decoding=\"async\" title=\"Image of formatted output displayed on screen\" alt=\"Image of formatted output displayed on screen\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/july\/hey0706\/hsg-07-06-09-02.jpg\" width=\"600\" height=\"491\"><\/p>\n<p class=\"MsoNormal\"><br>The reason the output is nicely formatted is the Windows PowerShell team created several format.ps1xml files that are used to control the way different objects are formatted when they are displayed. These XML files are located in the Windows PowerShell installation directory. Luckily, there is an automatic variable, <b>$pshome<\/b>, that can be used to refer to the Windows PowerShell installation directory. To obtain a listing of all the format.ps1xml files that are installed on your computer, use the <b>Get-ChildItem<\/b> cmdlet and specify a path that will retrieve any file with the name format in it. Pipeline the resulting <b>fileinfo<\/b> objects to the <b>Select-Object<\/b> cmdlet and choose the name property. This is seen here: <\/p>\n<p class=\"CodeBlockScreened\"><font size=\"1\"><font><font face=\"Lucida Sans Typewriter\">PS C:&gt; Get-ChildItem -Path $PSHOME\/*format* | Select-Object -Property name<\/p>\n<p>Name<br>&#8212;-<br>certificate.format.ps1xml<br>dotnettypes.format.ps1xml<br>filesystem.format.ps1xml<br>help.format.ps1xml<br>powershellcore.format.ps1xml<br>powershelltrace.format.ps1xml<br>registry.format.ps1xml<\/p>\n<p><\/font><\/font><\/font><\/p>\n<p class=\"MsoNormal\">These format.ps1xml files are used by the Windows PowerShell Extended Type System to determine how to display objects. This is required because most objects do not know how to display themselves. Because the format files are XML files, it is possible to edit them to change the default display behavior. This should not be undertaken lightly, though, because the files are rather complicated. If you wish to edit the files, make sure you have a good backup copy of the files before you start messing around with them. Direct manipulation of the format.ps1xml files could result in unexpected behavior. It is also possible to write your own format.ps1xml file (in fact Marc Van Orsouw [MOW] created his own format data file to tune the default output format for the <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/06\/21\/hey-scripting-guy-event-6-solutions-from-expert-commentators-beginner-and-advanced-the-110-meter-hurdles.aspx\">Trace-Route function he wrote<\/a> as a guest commentator for the <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/tags\/2009+Summer+Scripting+Games\/default.aspx\">2009 Summer Scripting Games<\/a>. <\/p>\n<p class=\"MsoNormal\">The dotnettypes.format.ps1xml file is used to control the output that is displayed by a number of the cmdlets (<b>Get-Process<\/b>, <b>Get-Service<\/b>, <b>Get-EventLog<\/b>, etc.) that return .NET Framework objects. A portion of the dotnettypes.format.ps1xml file is seen in the next image. This is the section of the file that controls the output from the <b>Get-Process<\/b> cmdlet that is seen in the previous image. Under the <b>&lt;TableHeaders&gt;<\/b> section, each column heading is specified by the <b>&lt;TableColumnHeader&gt;<\/b> tag. And under the <b>&lt;TableColumnHeader&gt;<\/b>, there are three nodes: <b>&lt;Label&gt;<\/b>, <b>&lt;Width&gt;<\/b>, and <b>&lt;Alignment&gt;<\/b>. <b>&lt;Label&gt; <\/b>controls the column heading, <b>&lt;Width&gt;<\/b> controls how wide the column is, and <b>&lt;Alignment&gt; <\/b>is used to specify the alignment (left, center, right) of the data within the column. This is seen here: <\/p>\n<p class=\"Fig-Graphic\"><span><\/span><\/p>\n<p><img decoding=\"async\" title=\"Image of code specifying table alignment\" alt=\"Image of code specifying table alignment\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/july\/hey0706\/hsg-07-06-09-03.jpg\" width=\"600\" height=\"491\"><\/p>\n<p class=\"MsoNormal\"><br>To display information in the Command Prompt window, you do not need to worry about format XML files or anything like that. You can rely upon the defaults and allow Windows PowerShell to make the decision for you. To display a string, you place the string in quotation marks and it is displayed in the Command Prompt window. This is seen here:<\/p>\n<p class=\"CodeBlockScreened\"><font size=\"1\"><font><font face=\"Lucida Sans Typewriter\">PS C:&gt; &#8220;this string is displayed to the console&#8221;<br>this string is displayed to the console<br>PS C:&gt;<\/p>\n<p><\/font><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The important thing to keep in mind is that when the string is shown in the Command Prompt window, it retains its type; that is, it is still a string. This is seen here: <\/p>\n<p class=\"CodeBlockScreened\"><font size=\"1\"><font><font face=\"Lucida Sans Typewriter\">PS C:&gt; &#8220;this string is displayed to the console&#8221; | Get-Member<\/p>\n<p><br><span>&nbsp;&nbsp; <\/span>TypeName: System.String<\/p>\n<p>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>MemberType<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Definition<br>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;-<br>Clone<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Object Clone()<br>CompareTo<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>int CompareTo(System.Object value), i&#8230;<br>Contains<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>bool Contains(string value)<br>CopyTo<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Void CopyTo(int sourceIndex, c&#8230;<br>EndsWith<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>bool EndsWith(string value), bool End&#8230;<br>Equals<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>bool Equals(System.Object obj), bool &#8230;<br>GetEnumerator<span>&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.CharEnumerator GetEnumerator()<br>GetHashCode<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>int GetHashCode()<br>GetType<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>type GetType()<br>GetTypeCode<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.TypeCode GetTypeCode()<br>IndexOf<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>int IndexOf(char value), int IndexOf(&#8230;<br>IndexOfAny<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>int IndexOfAny(char[] anyOf), int Ind&#8230;<br>Insert<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string Insert(int startIndex, string &#8230;<br>IsNormalized<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>bool IsNormalized(), bool IsNormalize&#8230;<br>LastIndexOf<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>int LastIndexOf(char value), int Last&#8230;<br>LastIndexOfAny<span>&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>int LastIndexOfAny(char[] anyOf), int&#8230;<br>Normalize<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string Normalize(), string Normalize(&#8230;<br>PadLeft<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string PadLeft(int totalWidth), strin&#8230;<br>PadRight<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string PadRight(int totalWidth), stri&#8230;<br>Remove<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;<\/span>string Remove(int startIndex, int cou&#8230;<br>Replace<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string Replace(char oldChar, char new&#8230;<br>Split<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string[] Split(Params char[] separato&#8230;<br>StartsWith<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>bool StartsWith(string value), bool S&#8230;<br>Substring<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string Substring(int startIndex), str&#8230;<br>ToCharArray<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>char[] ToCharArray(), char[] ToCharAr&#8230;<br>ToLower<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string ToLower(), string ToLower(Syst&#8230;<br>ToLowerInvariant Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string ToLowerInvariant()<br>ToString<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string ToString(), string ToString(Sy&#8230;<br>ToUpper<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string ToUpper(), string ToUpper(Syst&#8230;<br>ToUpperInvariant Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string ToUpperInvariant()<br>Trim<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string Trim(Params char[] trimChars),&#8230;<br>TrimEnd<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string TrimEnd(Params char[] trimChars)<br>TrimStart<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Method<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>string TrimStart(Params char[] trimCh&#8230;<br>Chars<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ParameterizedProperty char Chars(int index) {get;}<br>Length<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Int32 Length {get;}<\/p>\n<p><\/font><\/font><\/font><\/p>\n<p class=\"MsoNormal\">If you use one of the <b>Out-*<\/b> cmdlets such as <b>Out-Host<\/b> or <b>Out-Default<\/b>, you destroy the object-oriented nature of the string. That is, it is no longer an instance of a <b>system.string<\/b> .NET Framework class. This is seen here: <\/p>\n<p class=\"CodeBlockScreened\"><font size=\"1\"><font><font face=\"Lucida Sans Typewriter\">PS C:&gt; &#8220;this string is displayed to the console&#8221; | Out-Host | Get-Member<br>this string is displayed to the console<br>Get-Member : No object has been specified to the get-member cmdlet.<br>At line:1 char:66<br>+ &#8220;this string is displayed to the console&#8221; | Out-Host | Get-Member &lt;&lt;&lt;&lt;<br><span>&nbsp;&nbsp;&nbsp; <\/span>+ CategoryInfo<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: CloseError: (:) [Get-Member], InvalidOperationEx<br><span>&nbsp;&nbsp; <\/span>ception<br><span>&nbsp;&nbsp;&nbsp; <\/span>+ FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Command<br><span>&nbsp;&nbsp; <\/span>s.GetMemberCommand<\/p>\n<p>PS C:&gt;<\/p>\n<p><\/font><\/font><\/font><\/p>\n<p class=\"MsoNormal\">As a best practice you should avoid using the <b>Out-Host<\/b> cmdlet or the <b>Out-Default<\/b> cmdlet unless there is a reason for using it. This is because you lose your object after you send the output to these two cmdlets. The only reason for using <b>Out-Host<\/b> is to use the <b>&ndash;paging<\/b> parameter. This is seen here: <br><\/p>\n<p class=\"CodeBlockScreened\"><font size=\"1\"><font><font face=\"Lucida Sans Typewriter\">PS C:&gt; Get-WmiObject -Class win32_process | Out-Host -Paging<\/p>\n<p>__GENUS<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 2<br>__CLASS<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: Win32_Process<br>__SUPERCLASS<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: CIM_Process<br>__DYNASTY<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: CIM_ManagedSystemElement<br>__RELPATH<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: Win32_Process.Handle=&#8221;0&#8243;<br>__PROPERTY_COUNT<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 45<br>__DERIVATION<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: {CIM_Process, CIM_LogicalElement, CIM_ManagedSyste<br><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>mElement}<br>__SERVER<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: VISTA<br>__NAMESPACE<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: rootcimv2<br>__PATH<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: \\VISTArootcimv2:Win32_Process.Handle=&#8221;0&#8243;<br>Caption<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: System Idle Process<br>CommandLine<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>CreationClassName<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: Win32_Process<br>CreationDate<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>CSCreationClassName<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: Win32_ComputerSystem<br>CSName<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: VISTA<br>Description<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: System Idle Process<br>ExecutablePath<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;<\/span>:<br>ExecutionState<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>Handle<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br>HandleCount<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br>InstallDate<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>KernelModeTime<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 151488730096<br>MaximumWorkingSetSize<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>MinimumWorkingSetSize<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: System Idle Process<br>OSCreationClassName<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: Win32_OperatingSystem<br>OSName<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: Microsoftr Windows VistaT Business |C:Windows|De<br><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>viceHarddisk0Partition1<br>OtherOperationCount<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br>OtherTransferCount<span>&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>: 0<br>PageFaults<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br>PageFileUsage<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br>ParentProcessId<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br>PeakPageFileUsage<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br>PeakVirtualSize<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br>PeakWorkingSetSize<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br>Priority<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br>PrivatePageCount<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 0<br>&lt;SPACE&gt; next page; &lt;CR&gt; next line; Q quit<\/p>\n<p><\/font><\/font><\/font><\/p>\n<p class=\"MsoNormal\">If you are not using the paging parameter, there is no advantage to using the <b>Out-Host<\/b> cmdlet. From a display perspective, the following commands are identical:<\/p>\n<p class=\"CodeBlockScreened\"><font size=\"1\"><font><font face=\"Lucida Sans Typewriter\">Get-Process<\/p>\n<p><\/font><\/font><\/font><\/p>\n<p class=\"CodeBlockScreened\"><font size=\"1\"><font><font face=\"Lucida Sans Typewriter\">Get-Process | Out-Host<\/p>\n<p><\/font><\/font><\/font><\/p>\n<p class=\"CodeBlockScreened\"><font size=\"1\"><font><font face=\"Lucida Sans Typewriter\">Get-Process | Out-Default<\/p>\n<p><\/font><\/font><\/font><\/p>\n<p class=\"MsoNormal\">In fact, on most systems <b>Out-Default<\/b> and <b>Out-Host<\/b> do the same thing. This is because by default <b>Out-Host<\/b> is the default outputter. The only reason to use <b>Out-Default<\/b> would be if you anticipated changing the default outputter, and you did not want to rewrite the script. By using <b>Out-Default<\/b> the output from the script will always go to the default outputter, which may or may not be the host. <\/p>\n<p class=\"MsoNormal\">CO, that is about all there is to say for now about writing to the host. Join us tomorrow as we will continue talking about handling output from scripts. If you want to keep up to date with the Scripting Guys, you can follow us <a href=\"https:\/\/twitter.com\/scriptingguys\/\">on Twitter<\/a>. You can also look us up <a href=\"http:\/\/www.new.facebook.com\/group.php?gid=5901799452\">on Facebook<\/a>. Until tomorrow peace!<\/p>\n<p class=\"MsoNormal\"><b><span style=\"mso-bi\"><\/span><\/b><\/p>\n<\/h2>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! I am not into all those fancy scripts you seem to write. I am just a basic, everyday network administrator, and I simply need to use scripts to make my job easier. Because of this, I am not interested in displaying progress bars, writing stuff to Excel or Word or even PowerPoint. [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25,3,4,45],"class_list":["post-53013","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-displaying-output","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! I am not into all those fancy scripts you seem to write. I am just a basic, everyday network administrator, and I simply need to use scripts to make my job easier. Because of this, I am not interested in displaying progress bars, writing stuff to Excel or Word or even PowerPoint. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/53013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=53013"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/53013\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=53013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=53013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=53013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}