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

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Windows 2016 RDS event 1306 Connection Broker Client failed to redirect the user... Error: NULL