none
PowerShell Script to monitor disk size RRS feed

  • Question

  • Hello all,

                 I am learning Powershell and I am trying to make a basic powershell script that gets the disk information such as disk name,computername,Free space and total disk size.  I am getting the output I need but I want to show the output as Html page. I tired Convertto-Html cmdlet but could not figure out... Below is my script... 

    I am pretty sure there are already some scripts that do the same but as I said above, I learning powershell,so any help in fixing the script,will help me greatly to understand...

    $ComputerList =$env:COMPutername
    Write-Host "MachineName","Drive","DriveName","SizeInGB","FreeSizeInGB" -backgroundcolor 'RED'
    ForEach ($Computer in $ComputerList)
     {
    $A = Get-wmiobject win32_LogicalDisk -ComputerName $Computer | Select DeviceID,VolumeName,Size,FreeSpace  
    foreach($A1 in $A)
    { 
    $x=1073741824
    $y=$A1.Size/1073741824
    $z=$A1.FreeSpace/1073741824
    $y = "{0:N2}" -f$y
    $z= "{0:N2}" -f$z
    write-host $Computer,$A1.DeviceID,$A1.VolumeName,$y,$z|Sort-Object $Computer,$A1.DeviceID 
    }}

    Thank you


    Hope it Helps!!

    Monday, February 17, 2014 1:59 AM

Answers

  • Use help first:

    Get-wmiobject win32_LogicalDisk -ComputerName $Computer |
         Select DeviceID,VolumeName,Size,FreeSpace   |
         ConvertTo=Html

    It is that easy.


    ¯\_(ツ)_/¯


    • Edited by jrv Monday, February 17, 2014 5:24 AM
    • Marked as answer by Stan210 Tuesday, February 18, 2014 1:49 AM
    Monday, February 17, 2014 5:23 AM

All replies

  • Use help first:

    Get-wmiobject win32_LogicalDisk -ComputerName $Computer |
         Select DeviceID,VolumeName,Size,FreeSpace   |
         ConvertTo=Html

    It is that easy.


    ¯\_(ツ)_/¯


    • Edited by jrv Monday, February 17, 2014 5:24 AM
    • Marked as answer by Stan210 Tuesday, February 18, 2014 1:49 AM
    Monday, February 17, 2014 5:23 AM
  • cool..Thanks..The reason I was using ForEach is I was passing multiple MachineName but I did not realise

    we do not have to use it(i was confused here though)..the below works...

    $Computer = ("MachineA","MachineB")
    get-wmiobject win32_LogicalDisk -Computername $Computer | select DeviceID,VolumeName,Size,FreeSpace |convertto-Html |set-content <htmlfilepath>
    invoke-expression <htmlfilepath>

    but the below does not work,not sure why..

    I know,it works,if i use Foreach...

     but based on the above syntax working,I did not think it is needed. 

    $Instance = ("InstanceName1","InstanceName2")
    
    Invoke-SQLCmd -Query "Select database_id,Name,state_Desc,recovery_model_desc,page_verify_option_desc
    from master.sys.databases" -ServerInstance $Instance 

    any help appreciated....


    Hope it Helps!!

    Monday, February 17, 2014 6:03 AM
  • You need to learn the basics of PowerShell including how to use help.

    Start here and do the tutorials.  They will get you straightened out.

    http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx


    ¯\_(ツ)_/¯

    Monday, February 17, 2014 6:17 AM