Advanced Function Begin Clarification
hey everybody,
i'm curious if explain how being part works in function. know runs once, under impression run once , first. i've done example code below gives me error if try pipe in computername (using get-adcomputer.name) says computername null when creating cimsession. not understanding begin part correctly? works fine if move cimsession parts process. know can use get-ciminstance computername in it, wanted able open cimsession , pull several different cim classes info.
thanks if able clarify why is,
hunter
function get-driverversion { [cmdletbinding()] param ( [parameter(mandatory=$true,valuefrompipeline=$true)] [string]$computername, [parameter(mandatory=$true)] [string]$filter ) begin { $sessionoption = new-cimsessionoption -protocol dcom $cimsession = new-cimsession -computername $computername -sessionoption $sessionoption } process { #$sessionoption = new-cimsessionoption -protocol dcom #$cimsession = new-cimsession -computername $computername -sessionoption $sessionoption get-ciminstance -classname win32_pnpsigneddriver -cimsession $cimsession | select devicename, driverversion | {$_.devicename -like "*$filter*"} } end { remove-cimsession -cimsession $cimsession } }
the values pipeline available in the "process" section. parameters command line sent "begin".
get-adcomputer not have property called "computername". has "name" , "samaccountname"
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment