none
How to create powershell function for querying disk space RRS feed

  • Question

  • Hi

    I have script to query the disk space on remote computers.. can I convert it to function..

    if yes..please help how can I create a function to query on multiple servers


    ################################################

    $computers=Get-WmiObjectWin32_logicaldisk  -ComputerName  LocalHost` |Format-TablePSComputerName,DeviceID,MediaType,`

    @{Name="Size(GB)";Expression={[decimal]("{0:N0}"-f($_.size/1gb))}},`

    @{Name="Free Space(GB)";Expression={[decimal]("{0:N0}"-f($_.freespace/1gb))}},`

    @{Name="Free (%)";Expression={"{0,6:P0}"-f(($_.freespace/1gb) /($_.size/1gb))}} `
     
    -AutoSize


     
    $computers

    ########################################################
     
    Output


    PSComputerName DeviceID MediaType Size(GB) Free Space(GB) Free (%)
     -------------- -------- --------- -------- -------------- --------
     server1    C:              12      238            177   74 % 
     server1    D:               0     1000            817   82 % 
     server1    E:               0       10              4   41 %


    $computers=Get-WmiObjectWin32_logicaldisk  -ComputerName  LocalHost` |Format-TablePSComputerName,DeviceID,MediaType,`

    @{Name="Size(GB)";Expression={[decimal]("{0:N0}"-f($_.size/1gb))}},`

    @{Name="Free Space(GB)";Expression={[decimal]("{0:N0}"-f($_.freespace/1gb))}},`

    @{Name="Free (%)";Expression={"{0,6:P0}"-f(($_.freespace/1gb) /($_.size/1gb))}} `
     
    -AutoSize


     
    $computers

    Tuesday, July 25, 2017 5:34 AM

All replies