Windows Powershell - My 2nd Parameter doesnt seem to work
hi there,
i've created following function , created following parameters go it..
function start-precheck7{ [cmdletbinding()] param( [parameter(mandatory=$true,position=1)] [string]$filepath, [string]$computername )
using parameters i've got following lines of script -
get-itemproperty $filepath | select length | foreach-object {[math]::round($_.length / 1mb,2)}
and..
get-wmiobject -computername $computername win32_logicaldisk -filter "deviceid='c:'" | select freespace | foreach-object {[math]::round($_.freespace / 1mb,2)}
the $filepath line runs expected , $computername seems run but.. script have wont run if don't specify $computername want optional parameter may want run scrip on local machine.
could or advise tips make more effective
any questions please ask..
thanks
function start-precheck7{ [cmdletbinding()] param( [parameter(mandatory=$true,position=1)] [string]$filepath, [string]$computername ) if (!$computername) { $computername = $env:computername } ... }
or in param-listing:
param( [parameter(mandatory=$true,position=1)] [string]$filepath, [string]$computername = $env:computername )
Windows Server > Windows PowerShell
Comments
Post a Comment