none
Script to get Hard DriveTotal Disk Size, Utilize Space Size and Free Disk space

    Question

  • Hi All,

    i need a script to get Hard Drive Total Disk Size, Utilize Space Size and Free Disk space of my servers and send a report by email. Can anyone please help me in this.

    Regards,

    ZB

    Wednesday, November 13, 2013 10:13 AM

Answers

  • $from = "MailID"
    $to = "MailID"
    $smtp = "SMTP NAME"
    $subject = "Disk Space Report"

    Put in this variable

    Full code is here

    $comp= Get-Content "C:\Temp\Comp.txt"
    $diskvalue = @()
    foreach($pc in $comp)
    {
        $diskvalue += Get-WmiObject -Class Win32_logicaldisk -ComputerName $pc -Filter DriveType=3 | 
        Select SystemName , DeviceID , @{Name=”size(GB)”;Expression={“{0:N1}” -f($_.size/1gb)}}, @{Name=”freespace(GB)”;Expression={“{0:N1}” -f($_.freespace/1gb)}}
        $diskvalue | Export-Csv C:\Temp\DiskReport.csv -NoTypeInformation
    }
    Start-Sleep 5
    $from = "MailID"
    $to = "MailID"
    $smtp = "SMTP NAME"
    $subject = "Disk Space Report"
    Send-MailMessage -From $from -To $to -SmtpServer $smtp -Subject $subject -Body "Disk Space Report" -Attachments C:\Temp\DiskReport.csv
    In Mail ID assign your mail ID, SMTP name your SMTP address


    Regards Chen V [MCTS SharePoint 2010]


    Wednesday, November 13, 2013 5:01 PM

All replies

  • Use this Script

    http://gallery.technet.microsoft.com/scriptcenter/Disk-Space-Report-Excel-f727d54e


    Regards Chen V [MCTS SharePoint 2010]

    Wednesday, November 13, 2013 10:36 AM
  • This is great place to start with set your threshold as required

    Disk Space HTML format and sends e-mail


    Regards Chen V [MCTS SharePoint 2010]

    Wednesday, November 13, 2013 10:50 AM
  • Hi,

    This script is great but i want this excel file to send by email through script. Any idea ?

    Regards,

    ZB

    Wednesday, November 13, 2013 11:53 AM
  • Okay

    You saved your excel in C:\Temp\DiskSpace.xls then use the below code

    $from = "mailid"
    $to = "mailid"
    $smtp = "SMTP"
    $subject = "Disk Report"
    Send-MailMessage -From $from -To $to -Subject $subject -body "Disk Report" -SmtpServer $smtp -Attachments C:\Temp\Diskspace.csv

    Get in touch with your exchange team for SMTP address

    Give valid mail id's


    Regards Chen V [MCTS SharePoint 2010]



    • Edited by Chen VMVP Wednesday, November 13, 2013 11:59 AM
    Wednesday, November 13, 2013 11:57 AM
  • Do you need a script which does this job every day ?

    Regards Chen V [MCTS SharePoint 2010]

    Wednesday, November 13, 2013 12:12 PM
  • C:\Temp\Comp.txt should have your computer names like one after other

    COMP1

    COMP2

    Complete Code is here

    $comp= Get-Content "C:\Temp\Comp.txt"
    $diskvalue = @()
    foreach($pc in $comp)
    {
        $diskvalue += Get-WmiObject -Class Win32_logicaldisk -ComputerName $pc -Filter DriveType=3 | 
        Select SystemName , DeviceID , @{Name=”size(GB)”;Expression={“{0:N1}” -f($_.size/1gb)}}, @{Name=”freespace(GB)”;Expression={“{0:N1}” -f($_.freespace/1gb)}}
        $diskvalue | Export-Csv C:\Temp\DiskReport.csv -NoTypeInformation
    }
    Start-Sleep 5
    $from = "MailID"
    $to = "MailID"
    $smtp = "SMTP NAME"
    $subject = "Disk Space Report"
    Send-MailMessage -From $from -To $to -SmtpServer $smtp -Subject $subject -Body "Disk Space Report" -Attachments C:\Temp\DiskReport.csv
    get SMTP details from your exchange admin. Let me know if you need more help and assistance


    Regards Chen V [MCTS SharePoint 2010]

    Wednesday, November 13, 2013 12:26 PM
  • Yup i need this job to run everyday at 6:00 AM.

    Thanks for your kind support.

    Regards,

    ZB

    Wednesday, November 13, 2013 12:36 PM
  • You check the code I shared - Save that as PS1 and use Task Scheduler

    Regards Chen V [MCTS SharePoint 2010]

    Wednesday, November 13, 2013 12:37 PM
  • Thanks Chen i will check this code and will update you ASAP.

    Regards,

    ZB

    Wednesday, November 13, 2013 12:59 PM
  • You can download and modify the script from gallery

    Regards Chen V [MCTS SharePoint 2010]

    Wednesday, November 13, 2013 1:10 PM
  • Hi Chen,

    What values do i need to modify for smtp details in below command,

    Send-MailMessage -From $from -To $to -SmtpServer $smtp -Subject $subject -Body "Disk Space Report" -Attachments C:\Temp\DiskReport.csv

    Thanks & Regards,

    Zeeshan Butt

    Wednesday, November 13, 2013 3:45 PM
  • You should be knowing your SMTP address, you can check with your exchange administrators they can help you.

    Mostly it may be like SMTP.DOMAIN.NET or .COM or IP

    In Single Server Environment it will be your hub transport server FQDN or IP


    Regards Chen V [MCTS SharePoint 2010]


    • Edited by Chen VMVP Wednesday, November 13, 2013 3:48 PM
    Wednesday, November 13, 2013 3:47 PM
  • You try with you Outlook Web Mail URL for SMTP

    like site.domain.com - May give a dice.


    Regards Chen V [MCTS SharePoint 2010]

    Wednesday, November 13, 2013 3:56 PM
  • That is fine i know my smtp lets say may smtp is mail.contoso.com, sender id is test@contoso.com and reciever id is test2@contoso.com. How can i put these values in below command,

    Send-MailMessage -From $from -To $to -SmtpServer $smtp -Subject $subject -Body "Disk Space Report" -Attachments C:\Temp\DiskReport.csv

    Wednesday, November 13, 2013 4:54 PM
  • $from = "MailID"
    $to = "MailID"
    $smtp = "SMTP NAME"
    $subject = "Disk Space Report"

    Put in this variable

    Full code is here

    $comp= Get-Content "C:\Temp\Comp.txt"
    $diskvalue = @()
    foreach($pc in $comp)
    {
        $diskvalue += Get-WmiObject -Class Win32_logicaldisk -ComputerName $pc -Filter DriveType=3 | 
        Select SystemName , DeviceID , @{Name=”size(GB)”;Expression={“{0:N1}” -f($_.size/1gb)}}, @{Name=”freespace(GB)”;Expression={“{0:N1}” -f($_.freespace/1gb)}}
        $diskvalue | Export-Csv C:\Temp\DiskReport.csv -NoTypeInformation
    }
    Start-Sleep 5
    $from = "MailID"
    $to = "MailID"
    $smtp = "SMTP NAME"
    $subject = "Disk Space Report"
    Send-MailMessage -From $from -To $to -SmtpServer $smtp -Subject $subject -Body "Disk Space Report" -Attachments C:\Temp\DiskReport.csv
    In Mail ID assign your mail ID, SMTP name your SMTP address


    Regards Chen V [MCTS SharePoint 2010]


    Wednesday, November 13, 2013 5:01 PM
  • Thanks Chev you are Champion...
    Wednesday, November 13, 2013 5:05 PM
  • I am glad that it worked

    Regards Chen V [MCTS SharePoint 2010]

    Wednesday, November 13, 2013 5:06 PM
  • Dear Chen,

    I am not getting Disk Used Space from the script.

    Regards,

    ZB

    Thursday, November 14, 2013 8:18 AM
  • Dear Chen,

    I am not getting Disk Used Space from the script.


    Hi ZB, because we didn't added it in code. Used Space is nothing but Size - FreeSpace.

    Try this code and let me know

    $comp= Get-Content "C:\Temp\Comp.txt"
    $diskvalue = @()
    foreach($pc in $comp)
    {
        $diskvalue += Get-WmiObject -Class Win32_logicaldisk -ComputerName $pc -Filter DriveType=3 | 
        Select SystemName , DeviceID , @{Name=”size(GB)”;Expression={“{0:N1}” -f($_.size/1gb)}}, @{Name=”freespace(GB)”;Expression={“{0:N1}” -f($_.freespace/1gb)}}, @{Name=”UsedSpace(GB)”;Expression={“{0:N2}” -f($_.size - $_.FreeSpace/1gb)}}
        $diskvalue | Export-Csv C:\Temp\DiskReport.csv -NoTypeInformation
    }
    Start-Sleep 5
    $from = "MailID"
    $to = "MailID"
    $smtp = "SMTP NAME"
    $subject = "Disk Space Report"
    Send-MailMessage -From $from -To $to -SmtpServer $smtp -Subject $subject -Body "Disk Space Report" -Attachments C:\Temp\DiskReport.csv

    I added,

    @{Name=”UsedSpace(GB)”;Expression={“{0:N2}” -f($_.size - $_.FreeSpace/1gb)}


    Regards Chen V [MCTS SharePoint 2010]


    • Edited by Chen VMVP Thursday, November 14, 2013 10:31 AM
    Thursday, November 14, 2013 10:20 AM