O'Reilly logo

Learn PowerShell Toolmaking in a Month of Lunches by Don Jones and Jeffrey Hicks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.4. Accepting pipeline input

In our original design of the function, we said that we wanted –ComputerName to accept strings from the pipeline. It’s time to make that happen, as shown here.

Listing 8.4. Configuring –ComputerName to accept pipeline input
function Get-SystemInfo {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$True,ValueFromPipeline=$True)] [Alias('hostname')] [string[]]$ComputerName, [string]$ErrorLog = 'c:\retry.txt' ) BEGIN { Write-Verbose "Error log will be $ErrorLog" } PROCESS { foreach ($computer in $computername) { Write-Verbose "Querying $computer" $os = Get-WmiObject -class Win32_OperatingSystem ` -computerName $computer $comp = Get-WmiObject -class Win32_ComputerSystem ` -computerName $computer $bios = Get-WmiObject ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required