Formatting and why it s done on the right in VB.NET

Creation DataMatrix in VB.NET Formatting and why it s done on the right

Formatting and why it s done on the right
Print Data Matrix In Visual Basic .NET
Using Barcode generator for Visual Studio .NET Control to generate, create DataMatrix image in .NET applications.
www.OnBarcode.com
Data Matrix 2d Barcode Scanner In VB.NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Let s quickly review: you know that PowerShell cmdlets produce objects, and that those objects often contain more properties than PowerShell shows by default. You know how to use Gm to get a list of all of an object s properties, and you know how to use Select-Object to specify the properties you want to see. Up to now, you ve relied on PowerShell s default configuration and rules to determine how the final output will appear on the screen (or in a file, or in hardcopy form). In this chapter, you ll learn to override those defaults and create your own formatting for your commands output.
Encode Matrix 2D Barcode In Visual Basic .NET
Using Barcode maker for .NET framework Control to generate, create Matrix image in VS .NET applications.
www.OnBarcode.com
Generating EAN / UCC - 13 In VB.NET
Using Barcode encoder for Visual Studio .NET Control to generate, create UCC-128 image in Visual Studio .NET applications.
www.OnBarcode.com
Formatting: making what you see prettier
Data Matrix ECC200 Generation In VB.NET
Using Barcode creation for VS .NET Control to generate, create ECC200 image in VS .NET applications.
www.OnBarcode.com
QR Code JIS X 0510 Creator In VB.NET
Using Barcode encoder for VS .NET Control to generate, create QR Code JIS X 0510 image in Visual Studio .NET applications.
www.OnBarcode.com
I don t want to give you the impression that PowerShell is a full-fledged management reporting tool, because it isn t. But PowerShell has good capabilities for collecting information about computers, and, with the right output, you can certainly produce reports using that information. The trick, of course, is getting the right output, and that s what formatting is all about. On the surface, PowerShell s formatting system can seem pretty easy to use and for the most part that s true. But the formatting system also contains some of the trickiest gotchas in the entire shell, so I want to make sure you really understand how it works and why it does what it does. I m not just going to show you a few new commands here, but rather explain how the entire system works, how you can interact with it, and what limitations you might run into.
Print 1D In VB.NET
Using Barcode drawer for .NET framework Control to generate, create 1D Barcode image in .NET applications.
www.OnBarcode.com
Code 93 Full ASCII Maker In VB.NET
Using Barcode generation for Visual Studio .NET Control to generate, create ANSI/AIM Code 93 image in .NET framework applications.
www.OnBarcode.com
Formatting and why it s done on the right
Creating Data Matrix 2d Barcode In None
Using Barcode creation for Online Control to generate, create Data Matrix image in Online applications.
www.OnBarcode.com
DataMatrix Recognizer In C#
Using Barcode scanner for .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
About the default formatting
Making Barcode In .NET
Using Barcode maker for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
Paint Barcode In .NET
Using Barcode maker for ASP.NET Control to generate, create Barcode image in ASP.NET applications.
www.OnBarcode.com
Run our old friend Get-Process again, and pay special attention to the column headers. Notice that they don t exactly match the property names. Instead, they each have a specific width, alignment, and so forth. All that configuration stuff has to come from someplace, right You ll find it in one of the .format.ps1xml files that install with PowerShell. Specifically, formatting directions for process objects are in DotNetTypes .format.ps1xml. You ll definitely want to have PowerShell open so that you can follow along with what I m about to show you. This will really help you understand what the formatting system is up to under the hood.
Drawing Data Matrix In Visual Studio .NET
Using Barcode maker for Visual Studio .NET Control to generate, create Data Matrix ECC200 image in .NET applications.
www.OnBarcode.com
Barcode Drawer In None
Using Barcode drawer for Microsoft Word Control to generate, create Barcode image in Office Word applications.
www.OnBarcode.com
TRY IT NOW
Print Barcode In Java
Using Barcode creator for Android Control to generate, create Barcode image in Android applications.
www.OnBarcode.com
EAN13 Reader In .NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Start by changing to the PowerShell installation folder and opening DotNetTypes .format.ps1xml. Be careful not to save any changes to this file! It s digitally signed, and any changes that you save even a single carriage return or space added to the file will break the signature and prevent PowerShell from using the file.
Code-128 Generation In None
Using Barcode generation for Software Control to generate, create Code 128C image in Software applications.
www.OnBarcode.com
Generating USS Code 128 In None
Using Barcode generation for Online Control to generate, create ANSI/AIM Code 128 image in Online applications.
www.OnBarcode.com
PS C:\>cd $pshome PS C:\>notepad dotnettypes.format.ps1ml
Code 39 Extended Maker In None
Using Barcode creator for Word Control to generate, create Code 3 of 9 image in Office Word applications.
www.OnBarcode.com
Making QR Code In Java
Using Barcode maker for Android Control to generate, create Denso QR Bar Code image in Android applications.
www.OnBarcode.com
Next, find out the exact type of object returned by Get-Process:
PS C:\>get-process | gm
Now follow these steps:
Copy and paste the complete type name, System.Diagnostics.Process, to the clipboard. Do to so, use your cursor to highlight the type name, and press Return to copy it to the clipboard. Switch over to Notepad and press Ctrl-F to open the Find window. In the Find window, paste in the type name you copied to the clipboard. Click Find Next. The first thing you find will probably be a ProcessModule object, not a Process object, so click Find Next again and again until you locate System .Diagnostics.Process in the file. Figure 8.1 shows what you should have found.
What you re now looking at in Notepad is the set of directions that govern how a process is displayed by default. Scroll down a
Figure 8.1 Notepad
Locating the Process view in Windows
About the default formatting
bit, and you ll see the definition for a table view, which you should expect because you already know that processes display in a multicolumn table. You ll see the familiar column names, and if you scroll down a bit more you ll see where the file specifies which property will display in each column. You ll see definitions for column widths and alignments too. When you re done browsing, close Notepad, being careful not to save any changes that you may have accidentally made to the file, and go back to PowerShell. When you run Get-Process, here s what happens in the shell:
The cmdlet places objects of the type System.Diagnostics.Process into the pipeline. At the end of the pipeline is an invisible cmdlet called Out-Default. It s always there, and its job is to pick up whatever objects are in the pipeline after all of your commands have run. Out-Default passes the objects to Out-Host, because the PowerShell console is designed to use the screen (called the host) as its default form of output. In theory, someone could write a shell that uses files or printers as the default output instead, but nobody has that I know of. Most of the Out- cmdlets are incapable of working with normal objects. Instead, they re designed to work with special formatting instructions. So when OutHost sees that it has been handed normal objects, it passes them to the formatting system. The formatting system looks at the type of the object and follows an internal set of formatting rules (we ll cover those in a moment). It uses those rules to produce formatting instructions, which are passed back to Out-Host. Once Out-Host sees that it has formatting instructions, it follows those instructions to construct the onscreen display.
All of this happens whenever you manually specify an Out- cmdlet, too. For example, run Get-Process | Out-File procs.txt, and Out-File will see that you ve sent it some normal objects. It will pass those to the formatting system, which creates formatting instructions and passes them back to Out-File. Out-File then constructs the text file based on those instructions. So the formatting system becomes involved anytime objects need to be converted into human-readable textual output. What rules does the formatting system follow in step 5, above For the first formatting rule, the system looks to see if the type of object it s dealing with has a predefined view. That s what you saw in DotNetTypes.format.ps1xml: a predefined view for a Process object. There are a few other .format.ps1xml files installed with PowerShell, and they re all loaded by default when the shell starts. You can create your own predefined views as well, although doing so is beyond the scope of this book. The formatting system looks for predefined views that specifically target the object type it s dealing with meaning that in this case it s looking for the view that handles System.Diagnostics.Process objects.
Copyright © OnBarcode.com . All rights reserved.