Powershell confuses -computer with -computername
here script running:
$date = get-date -uformat "%b-%d-%y"
$location = "d:\ps_scripts\daily_volume_space\"
$path = $location += $date + ".csv"
gwmi -query "select systemname,caption,capacity,freespace win32_volume drivetype=3" -computer (gc d:\ps_scripts\servers.txt) | select-object systemname,caption, @{n="% free";e={"{0:p2}" -f ([long]$_.freespace/[long]$_.capacity)}}, @{name="freespace(gb)"; expression={"{0:n2}" -f ($_.freespace/1gb)}},@{name="size(gb)"; expression={"{0:n2}" -f ($_.capacity/1gb)}} | sort "% free" | export-csv $path -notypeinformation
error message
get-wmiobject : cannot validate argument on parameter 'computername'. argument null or empty. supply argument not nul
l or empty , try command again.
@ d:\ps_scripts\testscripts\volumespace_old.ps1:1 char:105
+ gwmi -query "select systemname,caption,capacity,freespace win32_volume drivetype=3" -computer <<<< (gc d:\ps_scripts\servers.txt) | select-object systemname,caption,@{name="size(gb)"; expression={"{0:n2}" -f ($_.capacity/1gb)}},@{name="freespace(g
b)"; expression={"{0:n2}" -f ($_.freespace/1gb)}}, @{n="% free";e={"{0:p2}" -f ([long]$_.freespace/[long]$_.capacity)}} | sort "% free"
| export-csv d:\dssstage\ps_scripts\disk-gb.csv -notypeinformation
+ categoryinfo : invaliddata: ( [get-wmiobject], parameterbindingvalidationexception
+ fullyqualifiederrorid : parameterargumentvalidationerror,microsoft.powersh ell.commands.getwmiobjectcommand
script has been running fine weeks. i'm not sure why powershell thinks -computer shorthand -computername. suggestions?
$date = get-date -uformat "%b-%d-%y"
$location = "d:\ps_scripts\daily_volume_space\"
$path = $location += $date + ".csv"
gwmi -query "select systemname,caption,capacity,freespace win32_volume drivetype=3" -computer (gc d:\ps_scripts\servers.txt) | select-object systemname,caption, @{n="% free";e={"{0:p2}" -f ([long]$_.freespace/[long]$_.capacity)}}, @{name="freespace(gb)"; expression={"{0:n2}" -f ($_.freespace/1gb)}},@{name="size(gb)"; expression={"{0:n2}" -f ($_.capacity/1gb)}} | sort "% free" | export-csv $path -notypeinformation
error message
get-wmiobject : cannot validate argument on parameter 'computername'. argument null or empty. supply argument not nul
l or empty , try command again.
@ d:\ps_scripts\testscripts\volumespace_old.ps1:1 char:105
+ gwmi -query "select systemname,caption,capacity,freespace win32_volume drivetype=3" -computer <<<< (gc d:\ps_scripts\servers.txt) | select-object systemname,caption,@{name="size(gb)"; expression={"{0:n2}" -f ($_.capacity/1gb)}},@{name="freespace(g
b)"; expression={"{0:n2}" -f ($_.freespace/1gb)}}, @{n="% free";e={"{0:p2}" -f ([long]$_.freespace/[long]$_.capacity)}} | sort "% free"
| export-csv d:\dssstage\ps_scripts\disk-gb.csv -notypeinformation
+ categoryinfo : invaliddata: ( [get-wmiobject], parameterbindingvalidationexception
+ fullyqualifiederrorid : parameterargumentvalidationerror,microsoft.powersh ell.commands.getwmiobjectcommand
script has been running fine weeks. i'm not sure why powershell thinks -computer shorthand -computername. suggestions?
there wrong file that’s sure... perhaps blank
line?
also, follow mean param stuff?
if powershell can figure out param based on give it,
will use full name of param
so, cant type -c because there 3 params start c,
you can -co because 1 starts co (computername)
you -compute if wanted, or -computern full param
name computername, if put in enough powershell knows
which param is, fine..
your problem being passed -computername (the contents of
that file) screwing command.. because null or empty..
pull file in
$servers = gc d:\ps_scripts\servers.txt
$servers
$servers | gwmi -query "select systemname,caption,capacity,freespace
win32_volume drivetype=3" | select-object systemname,caption, @{n="%
free";e={"{0:p2}" -f ([long]$_.freespace/[long]$_.capacity)}},
@{name="freespace(gb)"; expression={"{0:n2}" -f
$_.freespace/1gb)}},@{name="size(gb)"; expression={"{0:n2}" -f
($_.capacity/1gb)}} | sort "% free" | export-csv $path -notypeinformation
justin rich
http://jrich523.wordpress.com
please remember mark replies answers if , unmark them if provide no help.
Windows Server > Windows PowerShell
Comments
Post a Comment