Jörgen Fält
hi i'm trying write function in powershell. want free space of harddrive c: , computernames computers specified in names.txt
function driveinfo {
process {
$disk = gwmi win32_logicaldisk -computer $_
$obj = new-psobject
$obj | add-member noteproperty computername $_
$obj | add-member noteproperty volym $disk.deviceid
$obj | add-member noteproperty free space $disk.freespace
write-output $obj
}
}
get-content c:\powershell\names.txt | driveinfo | export-csv c:\powershell\export_from_driveinfo.csv
a couple of pieces missing , syntax errors.
function driveinfo {param ([array]$computers) process { $disk = gwmi win32_logicaldisk -computer $_ -filter 'name="c:"' $obj = new-object psobject $obj | add-member noteproperty computername $_ $obj | add-member noteproperty volym $disk.deviceid $obj | add-member noteproperty 'free space' $disk.freespace write-output $obj } }
get-content c:\powershell\names.txt | driveinfo | export-csv c:\powershell\export_from_driveinfo.csv
inspired carlsberg.
Windows Server > Windows PowerShell
Comments
Post a Comment