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

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

Event ID 64,77,1008 Certificates Events Windows Server 2008, 2008R2