c# barcode zebra printer Get-DiskInventory.ps1, with an additional parameter in VB.NET

Encode ECC200 in VB.NET Get-DiskInventory.ps1, with an additional parameter

Listing 17.3 Get-DiskInventory.ps1, with an additional parameter
Print Data Matrix In VB.NET
Using Barcode creation for Visual Studio .NET Control to generate, create ECC200 image in .NET framework applications.
www.OnBarcode.com
Scanning Data Matrix In Visual Basic .NET
Using Barcode reader for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
param ( Specifying additional $computername = 'localhost', parameter $drivetype = 3 ) Get-WmiObject -class Win32_LogicalDisk -computername $computername ` -filter "drivetype=$drivetype" | Using parameter Sort-Object -property DeviceID | Format-Table -property DeviceID, @{l='FreeSpace(MB)';e={$_.FreeSpace / 1MB -as [int]}},
Print Matrix Barcode In Visual Basic .NET
Using Barcode maker for .NET Control to generate, create 2D Barcode image in VS .NET applications.
www.OnBarcode.com
UPCA Drawer In VB.NET
Using Barcode creation for .NET framework Control to generate, create UPCA image in .NET applications.
www.OnBarcode.com
You call this scripting
Barcode Drawer In Visual Basic .NET
Using Barcode printer for Visual Studio .NET Control to generate, create Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Making Code 39 In VB.NET
Using Barcode printer for VS .NET Control to generate, create Code 3 of 9 image in Visual Studio .NET applications.
www.OnBarcode.com
@{l='Size(GB';e={$_.Size / 1GB -as [int]}}, @{l='%Free';e={$_.FreeSpace / $_.Size * 100 -as [int]}}
Generate EAN13 In VB.NET
Using Barcode printer for .NET Control to generate, create EAN13 image in .NET applications.
www.OnBarcode.com
Code 11 Creation In VB.NET
Using Barcode drawer for .NET Control to generate, create Code 11 image in Visual Studio .NET applications.
www.OnBarcode.com
Notice that I took advantage of PowerShell s ability to replace variables with their values inside of double quotation marks (you learned about that trick in chapter 15). I can run this script in any of the three original ways, although I could also omit either parameter if I wanted to use the default value for it. Here are some permutations:
DataMatrix Reader In VB.NET
Using Barcode decoder for .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Generate ECC200 In None
Using Barcode creation for Software Control to generate, create DataMatrix image in Software applications.
www.OnBarcode.com
PS PS PS PS C:\> C:\> C:\> C:\> .\Get-DiskInventory.ps1 .\Get-DiskInventory.ps1 .\Get-DiskInventory.ps1 .\Get-DiskInventory.ps1 server-r2 3 -comp server-r2 -drive 3 server-r2 -drive 3
Barcode Creation In None
Using Barcode generation for Microsoft Word Control to generate, create Barcode image in Office Word applications.
www.OnBarcode.com
Code-39 Generator In Java
Using Barcode encoder for Java Control to generate, create Code39 image in Java applications.
www.OnBarcode.com
In the first instance, I specified both parameters positionally, in the order in which they re declared within the Param() block. In the second case, I specified abbreviated parameter names for both. The third time, I omitted -drivetype entirely, using the default value of 3. In the last instance, I left off -computername, using the default value of localhost.
Barcode Reader In None
Using Barcode recognizer for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
UPC Symbol Printer In C#.NET
Using Barcode drawer for Visual Studio .NET Control to generate, create UPC Symbol image in .NET framework applications.
www.OnBarcode.com
17.5 Documenting your script
Printing Data Matrix In Java
Using Barcode printer for Android Control to generate, create Data Matrix ECC200 image in Android applications.
www.OnBarcode.com
Draw UPC - 13 In Java
Using Barcode printer for Java Control to generate, create EAN 13 image in Java applications.
www.OnBarcode.com
Only a truly mean person would create a useful script and not tell anyone how to use it. Fortunately, PowerShell makes it easy to add help into your script, using comments. You re welcome to add typical programming-style comments to your scripts, but if you re using full cmdlet and parameter names, sometimes your scripts operation will be obvious. By using a special comment syntax, however, you can provide help that mimics PowerShell s own help files. The next listing shows what I ve added to my script.
Read QR Code JIS X 0510 In VB.NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
QR Code JIS X 0510 Maker In Objective-C
Using Barcode printer for iPad Control to generate, create Quick Response Code image in iPad applications.
www.OnBarcode.com
Listing 17.4 Adding help to Get-DiskInventory.ps1
Code 128 Encoder In Java
Using Barcode maker for Android Control to generate, create ANSI/AIM Code 128 image in Android applications.
www.OnBarcode.com
Print UPC-A In .NET Framework
Using Barcode generator for .NET framework Control to generate, create GS1 - 12 image in VS .NET applications.
www.OnBarcode.com
<# .SYNOPSIS Get-DiskInventory retrieves logical disk information from one or more computers. .DESCRIPTION Get-DiskInventory uses WMI to retrieve the Win32_LogicalDisk instances from one or more computers. It displays each disk's drive letter, free space, total size, and percentage of free space. .PARAMETER computername The computer name, or names, to query. Default: Localhost. .PARAMETER drivetype The drive type to query. See Win32_LogicalDisk documentation for values. 3 is a fixed disk, and is the default. .EXAMPLE Get-DiskInventory -computername SERVER-R2 -drivetype 3 #> param ( $computername = 'localhost', $drivetype = 3 )
Documenting your script
Get-WmiObject -class Win32_LogicalDisk -computername $computername ` -filter "drivetype=$drivetype" | Sort-Object -property DeviceID | Format-Table -property DeviceID, @{l='FreeSpace(MB)';e={$_.FreeSpace / 1MB -as [int]}}, @{l='Size(GB';e={$_.Size / 1GB -as [int]}}, @{l='%Free';e={$_.FreeSpace / $_.Size * 100 -as [int]}}
Normally, PowerShell ignores anything on a line that follows a # symbol, meaning that # designates a line as a comment. I ve used a <# #> block comment syntax instead, because I had several lines of comments and didn t want to have to start each line with a separate # character. Now I can drop to the normal console host and ask for help by running help .\Get-DiskInventory (again, you have to provide a path because this is a script and not a built-in cmdlet). Figure 17.2 shows the results, which proves that PowerShell is reading those comments and creating a standard help display. I can even run help .\Get-DiskInventory -full to get full help, including parameter information and my example. Figure 17.3 shows those results. These special comments, called comment-based help, must appear at the beginning of your script file. There are several keywords in addition to .DESCRIPTION, .SYNOPSIS, and the others I ve used. For a full list, run help about_comment_ based_help in PowerShell.
Viewing the help by using the normal help command
You call this scripting
Figure 17.3 Help options like -example, -detailed, and -full are supported for comment-based help.
17.6 One script, one pipeline
I normally tell folks that anything in a script will run exactly as if you manually typed it into the shell, or if you copied the script to the clipboard and pasted it into the shell. That s not entirely true, though. Consider this simple script:
Copyright © OnBarcode.com . All rights reserved.