Announcement

Collapse
No announcement yet.

Powershell error, PS confuses -computer with -computername

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Powershell error, PS confuses -computer with -computername

    Here is the script I am 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 FROM win32_volume WHERE 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

    The error message is

    Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not nul
    l or empty and then try the command again.
    At D:\PS_scripts\testscripts\VolumeSpace_old.ps1:1 char:105
    + gwmi -query "SELECT SystemName,Caption,Capacity,Freespace FROM win32_volume WHERE 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

    This script has been running fine for weeks. I'm not sure why Powershell now thinks -computer is shorthand for -computername. Any suggestions?

  • #2
    Re: Powershell error, PS confuses -computer with -computername

    I fixed it. There were 2 blank lines at the end of list of servers in my text file.

    Comment

    Working...
    X