Powershell - Daily disk and folder usage; trouble with code to loop through the individual folders

Hi,
I'm very new to Powershell but through the help of this forum and the help on the internet I have scraped together a script that will loop through the disks of a set of servers listed in a text document, and give the capacity statistics in html
format.
I have two questions. I've tried modifying this to also loop though the individual folders on each disk and give the amount of space used to no avail. does any one have any suggestions?
Secondly, how do I get this to append? all I want to do is set up a scheduled task that runs this report daily. I know I will need to add a date column, but I just want the data to append to the previous set of results.
Thanks for any advice in advance.
# Continue even if there are errors
$ErrorActionPreference = "Continue";
# Set your warning and critical thresholds
$percentWarning = 100;
$percentCritcal = 15;
# REPORT PROPERTIES
# Path to the report
$reportPath = "C:\";
# Report name
$reportName = "DiskSpaceReport_$(get-date -format ddMMyyyy).html";
# Path and Report name together
$diskReport = $reportPath + $reportName
#Set colors for table cell backgrounds
$redColor = "#FF0000"
$orangeColor = "#FBB917"
$whiteColor = "#FFFFFF"
# Count if any computers have low disk space. Do not send report if less than 1.
$i = 0;
# Get computer list to check disk space
$computers = Get-Content "C:\serverlist.txt";
$datetime = Get-Date -Format "dd-MM-yyyy_HHmmss";
# Create and write HTML Header of report
$titleDate = get-date -uformat "%d-%m-%Y - %A"
$header = "
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<title>DiskSpace Report</title>
<STYLE TYPE='text/css'>
<!--
td {
font-family: Calibri;
font-size: 12px;
border-top: 1px solid #999999;
border-right: 1px solid #999999;
border-bottom: 1px solid #999999;
border-left: 1px solid #999999;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
body {
margin-left: 5px;
margin-top: 5px;
margin-right: 0px;
margin-bottom: 10px;
table {
border: thin solid #000000;
-->
</style>
</head>
<body>
<table width='100%'>
<tr bgcolor='#0B6121'>
<td colspan='7' height='30' align='center'>
<font face='calibri' color='#E0F8F7' size='4'><strong>Daily Disk Utilization Report for $titledate</strong></font>
</td>
</tr>
</table>
Add-Content $diskReport $header
# Create and write Table header for report
$tableHeader = "
<table width='100%'><tbody>
<tr bgcolor=#E0F8F7>
<td width='10%' align='center'>Server</td>
<td width='5%' align='center'>Drive</td>
<td width='15%' align='center'>Drive Label</td>
<td width='10%' align='center'>Total Capacity(GB)</td>
<td width='10%' align='center'>Used Capacity(GB)</td>
<td width='10%' align='center'>Free Space(GB)</td>
<td width='5%' align='center'>Freespace %</td>
<td width='5%' align='center'>RAM %</td>
<td width='5%' align='center'>CPU %</td>
</tr>
Add-Content $diskReport $tableHeader
# Start processing disk space
foreach($computer in $computers)
$disks = Get-WmiObject -ComputerName $computer -Class Win32_LogicalDisk -Filter #"DriveType = 3"
$computer = $computer.toupper()
foreach($disk in $disks)
$deviceID = $disk.DeviceID;
$volName = $disk.VolumeName;
[float]$size = $disk.Size;
[float]$freespace = $disk.FreeSpace;
$percentFree = [Math]::Round(($freespace / $size) * 100);
$sizeGB = [Math]::Round($size / 1073741824, 2);
$freeSpaceGB = [Math]::Round($freespace / 1073741824, 2);
$usedSpaceGB = $sizeGB - $freeSpaceGB;
$color = $whiteColor;
# Start processing RAM
$RAM = Get-WmiObject -ComputerName $computer -Class Win32_OperatingSystem
$RAMtotal = $RAM.TotalVisibleMemorySize;
$RAMAvail = $RAM.FreePhysicalMemory;
$RAMpercent = [Math]::Round(($RAMavail / $RAMTotal) * 100);
# Set background color to Orange if just a warning
if($percentFree -lt $percentWarning)
$color = $orangeColor
# Set background color to Orange if space is Critical
if($percentFree -lt $percentCritcal)
$color = $redColor
# Create table data rows
$dataRow = "
<tr>
<td width='10%'>$computer</td>
<td width='5%' align='center'>$deviceID</td>
<td width='10%' >$volName</td>
<td width='10%' align='center'>$sizeGB</td>
<td width='10%' align='center'>$usedSpaceGB</td>
<td width='10%' align='center'>$freeSpaceGB</td>
<td width='5%' bgcolor=`'$color`' align='center'>$percentFree</td>
<td width='5%' align='center'>$RAMpercent</td>
<td width='5%' align='center'>$CPUpercent</td>
</tr>
Add-Content $diskReport $dataRow;
Write-Host -ForegroundColor DarkYellow "$computer $deviceID percentage free space = $percentFree";
$i++
# Create table at end of report showing legend of colors for the critical and warning
$tableDescription = "
</table><br><table width='20%'>
<tr bgcolor='White'>
<td width='10%' align='center' bgcolor='#FBB917'>No Warning</td>
<td width='10%' align='center' bgcolor='#FF0000'>Critical less than 10% free space</td>
</tr>
Add-Content $diskReport $tableDescription
Add-Content $diskReport "</body></html>"

The only easy way to create a report like this that accumulates is to design it so the data is output to a CSV file or a database.  YOu can then generate the HTML from the persist6ed data.
If you store as XML you can use XSLT (transform) to convert to an HTML report.
I also recommend uing Excel as an HTML report generator.  It is much easier and more flexible.  PowerShell is not intended to do what you want without designing a whole custom reporting system.
Use the right tool for the right task.
Just because you own a hammer does not mean that the solution to every problem includes a nail.
¯\_(ツ)_/¯

Similar Messages

  • Anyone having trouble with operating music controls through the control center?

    Sometimes I pause my music to do something else. When I swipe up later to access the control center, I hit the play button, but it won't play. I could hit the button on my headphones to play but still no result. I have to actually open the music app and press play. Is anyone else having this problem?

    IslandPrince89 wrote:
    That actually helped but it seems that there are a lot of bugs in the iOS 7.0.2 ..
    You can use this Link to send your Feedback to Apple
    http://www.apple.com/feedback/

  • I'm working with Illustrator CS5 and am having trouble with basic graphics textures.

    I'm working with Illustrator CS5 and am having trouble with basic graphics textures. The illustrator drawings look fine with the pattern fills and when I bring the drawing into quark 9.1 they are still fine. When I print the quark file to lo res pdf drawing is still fine, but when I print to hi res pdf (press quality for print) the patterns disappear. I cannot figure out what the problem is.
    just a note. Other textures and artistic fills work fine. It seems to be just the basic ones. I'm wondering if for some reason they may not be saved completely in my libraries?

    Its just a drawing in black and white with some basic graphic texture to show “dirt”  The pattern consists of a bunch of small lines. I save the file as an eps. And bring it into quark.  When I print from quark I say print to pdf as press quality. I don’t think the problem has to do with acrobat because I’ve never encountered these problems before CS5. These drawings have been around for years and all of a sudden they don’t work.
    Does this help?
    Cath
    Graphic Specialist
    [email protected] 905-403-8658 x297
    P Is it necessary to print this e-mail?

  • HT1338 I have a Leopard desktop 10.5.8 and I have trouble with MAIL. My draft folder does not work and my draft messages will not delete.        delete

    I have a Leopard desktop 10.5.8 and I have trouble with my Email Apple MAIL draft folder. First of all after I typed my draft and sent to draft, the folder would not open at a later date to send. In all I have 10 messages, mainly test which I cannot delete from my Draft folder.
    My draft system is now working but I cannot get rid of the  10 messages which sit in my INBOX and DRAFT folders.
    These messages appear in Application - Mail but they will not go.
    How do I delete, or is it best to use My Disc 1# and delete all my software and replace with the Disc in order to have a new MAIL program?
    Any advice would be welcome.

    HI,
    Not certain, but this can fix myriad Mail problems...
    Safe Boot from the HD, (holding Shift key down at bootup),  it will try to repair your Disk Directory while the spinning radian is happening, so let it go, run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, then move this folder & file to the Desktop.
    Move this Folder to the Desktop...
    /Users/YourUserName/Library/Caches/Mail/
    Move this file to the Desktop...
    /Users/YourUserName/Library/Mail/Envelope Index
    Reboot.
    If that doesn't do it and you can afford to redo all your Rules, try these & reboot...
    /Users/YourUserName/Library/Mail/MessageRules.plist
    /Users/YourUserName/Library/Mail/MessageRules.plist.backup
    Note, in 10.5 & up /Users/YourUserName/Library/Caches/Mail/ may or may not exist.

  • So i have a 2011 MacBook Pro and when i turned it on this morning a flashing folder came on with a question mark in the middle of it and it keeps flashing. So i tried googling any solutions and up so far nothing has worked. Please Help ?

    I tried googling several solutions, but so far nothing seems to work. Everytime i start up my laptop i press CMND+R to make it go to the repair disk utility but instead it takes me as if i have to install lion when i had Snow Leopard 10.6.8. When i do go to the repair disk utility, on the eft hand side shows two hardrives one is Untitled and another is Hitachi, i tried downloading snow leopard 10.6.8 onto a Re-writable disc  using my windows computer. When i insterted it onto the disc drive it came out under SUPER DRIVE and everytime i double click on the CD it says something about attaching images/ I also forgot to mention that the MAC OSX 10.6.8 Update shows on the left hand side on the bottom in DMG format. I dont know what else to do, please help?

    DestroyGalaxies wrote:
    a flashing folder came on with a question mark in the middle of it
    This is the firmware telling you it can't find a bootable OS X volume.
    Usually to solve this all you do is hold the option key down on the built in keyboard while booting the computer, this enters Startup Manager and then you choose OS X to boot, then in System Preferences > Startup Disk you change it to the boot volume and it tells the firmware.
    Everytime i start up my laptop i press CMND+R to make it go to the repair disk utility but instead it takes me as if i have to install lion when i had Snow Leopard 10.6.8.
    What you have is a 10.7 or 10.8 Recovery HD from when 10.7 or 10. was on the machine previously.
    The Macintosh HD partition only was erased and 10.6 installed on it, without erasing the entire drive like what should have occured to remove the Recovery HD partition.
    So you have a mucked up machine.
    i tried downloading snow leopard 10.6.8 onto a Re-writable disc  using my windows computer.
    Well there goes your problem there, your downloading illegal copies of Snow Leopard from a untrusted location.
    10.6 is not available for download, except from pirate sites. You likely have malware or a compromised system.
    I dont know what else to do, please help?
    What you need to do is call Apple via phone, tell them the make of your machine and order the appropriate 10.6 disks, they are inexpensive now. Some machines that came with 10.6.3+ origianlly need machine specific disks, other wise pre-10.6.3 Intel Macs can use the 10.6.3 white retail disks.
    Once you have the disks, you need to backup your personal information off the computer to a external storage drive using the emergency quick copy method, then disconnect it to prevent mistakes.
    Most commonly used backup methods
    Next follow this proceedure and make sure to select the ENTIRE drive on the far left with the drive makers name and size, this will erase the entire drive, then install 10.6 from the disk
    How to erase and install Snow Leopard 10.6
    When finished setup the machine and log onto the Internet and use Software Update to get current on 10.6.8
    Don't use pirated software, it's likely been compromised in some fashion.

  • Scratch disks and RAM usage

    i would like to understand the relationship between scratch disks and RAM usage in Photoshop.
    While i was working on a fairly big psb file (2gb), photoshop kept prompting that I was out of memory, but in fact the utilization was only 75% (i had 16gbs total, photoshop was only using 7gb, and i allowed PS to use up to 14gb in total). when it says out of memory, it was actually my scratch disk at fault ( i only set 1 scratch disk, which was my 120gb SSD running out of space).
    any idea how I can optimize PS to use up all my RAM first before even touching my scratch disk? (short of using a RAMdisk, please).
    thanks!

    I am curious about this also. I just reinstalled W-7--have 11 G of physical memory--a ton of hard drive empty space also, and I have been wondering why PS_CC is so slow--since basically I have only put my Security and Browser in addition to Adobe back on the Dell XPS computer..... At least now it does show the downloading percentage (like .psd file) , but that must be what is happening.  I do think that some of these "frozen" screens I have been experiencing, was because the program was using scratch disk, instead of the Ram... I came up from CS-5, and can't describe it in detail, but just realize how slow PS-CC is in most everything.  Going back and see if reallocating will help...

  • I have been having trouble with my iphone 4 for the past day . i tried to update it to 7.0.4 then the screen went blank and it keeps telling me to connect to itunes . I have connected it to 2 computers , using different cords

    I have been having trouble with my iphone 4 for the past day . i tried to update it to 7.0.4 then the screen went blank and it keeps telling me to connect to itunes . I have connected it to 2 computers , using different cords and it doesnt recognize it . It says it is in recovery mode and i need to restore . after clicking restore it says that my iphone cannot be restored . I am very frustrated because i have been online searching for solutions all day and nothing seems to work . As soon as i turn on my phone it goes to the apple logo for about 2 seconds then the connect to itunes screen . SOMEBODY PLEASE HELP ! my phone is my life and i need it back on .

    Connect the device to iTunes and restore from the most current backup.
    If the issue continues, restore as new.

  • Just bought a new iPhone and am having trouble with iTunes and App Store. I can log in to Cloud, iTunes, and app store but once I try to download, it says "Youe apple id has been disabled". I've reset my password three times and have no issue on my Pad.

    Just bought a new iPhone and am having trouble with iTunes and App Store. I can log in to Cloud, iTunes, and app store but once I try to download, it says "Youe apple id has been disabled". I've reset my password three times and have no issue on my Pad.

    Hi FuzzyDunlopIsMe,
    Welcome to the Support Communities!
    It's possible that resetting your password multiple times has triggered this security.  Click on the link below for assistance with your Apple ID Account:
    Apple ID: Contacting Apple for help with Apple ID account security
    http://support.apple.com/kb/HT5699
    Here is some additional information regarding your Apple ID:
    Apple ID: 'This Apple ID has been disabled for security reasons' alert appears
    http://support.apple.com/kb/ts2446
    Frequently asked questions about Apple ID
    http://support.apple.com/kb/HT5622
    Click on My Apple ID to access and edit your account.
    Cheers,
    - Judy

  • My wife and I share apple id but have our own phones, and now having trouble with imessage

    My wife and I share apple id but have our own phones, and now having trouble with imessage. Sharing calenders, apps, music, contacts, etc...all great. But when we imessage each other. Our phones get confused and either not deliver message, or send it to and from itself.

    Go to Settings > Facetime and you will see "You can be reached for video calls at:"
    This should list your phone number (iPhone) and your email address (probably the gmail one).
    And then an option for "Add another email..."
    Choose that and enter your @me.com account and it'll send a verification email.
    Same for iMessage: Settings > Messages > "Receive at" > Add Another Email
    So you can be called by facetime and use iMessage through multiple email accounts yes.

  • Several of us have a iPhone 6s and are having trouble with hearing and speaking at the same time when using the phone. ? The speakers seem to be too far apart? Are others having this issue? Solutions?

    Several of us have a iPhone 6plus and are having trouble with hearing and speaking at the same time when using the phone. ? The speakers seem to be too far apart? Are others having this issue? Solutions?

    Not having the problem, don't personally know anyone who is.

  • I have 64-bit Vista on an HP laptop, and am having trouble with P4

    I have 64-bit Vista on an HP laptop, and am having trouble with P4. When I go to the "Compatibility" tab in for the P4 .exe file, 32-bit Vista does not show up as a compatibility option. The latest version shown is XP with SP2. Am I missing something? Is there a patch or download that updates P4?(The problem I'm having is stuttering and stopping in the imported avi2 files I have downloaded from my Panasonic digital camcorder and converted from avi to avi2 using DVDate. Also, I get stuttering with digital photos - jpg files - that I want to insert in the movie with added narration.)

    A.T. Romano
    It gets a little complicated. This is a simplification, but I hope this
    helps to visualize what's happening.
    The 32 bit and 64 bit environments are separated from each other.
    There are separate program files directories, separate shared dll library
    directories, and even separate registry entries. You can't mix 32 and
    64 bit modules, and some applications, like Internet Explorer, install
    both a 32 bit and a 64 bit version on the same computer. (IE does that
    so it can process web pages that use 32 bit executable controls).
    Vista 64 has 32 bit emulation built-in using a subsystem called Windows
    on Windows 64 or WOW64 for short. WOW64 intercepts 32 bit
    application calls to the operating system and handles the 32 to 64 bit
    conversions and the redirection of the file and registry locations.
    The program files themselves contain flags that indicate whether they
    are 32 bit and whether the file uses the 64 bit version of the file
    structure.
    If the program is marked 32 bit, it will run in 32 bit using WOW64.
    Programs are generally installed by an installer program which places
    the application files in the proper locations and writes the registry
    entries and any other setup tasks that are needed. To install a 64
    bit program, a 64 bit installer is needed. For 32 bit installers, the files
    and registry entries are redirected to the 32 bit locations.

  • I have a macbook and was having trouble with safari so I removed it and am trying to re-download but it says snow leopard and lion are too big. which version of safari can i download?

    I have a macbook and was having trouble with safari so I removed it and am trying to re-download but it says snow leopard and lion are too big. which version of safari can i download?

    Which operating system are you running? Not sure, click the apple on the left of the menu bar, the click about this mac. It will say version 10.6.x or 10.7.x.

  • I recently joined Pinterest and am having trouble with it on Firefox.

    I recently joined Pinterest and am having trouble with it on Firefox. I am able to load the website but unable to repin and pin my own items. The site works slowly but fine on IE. Any ideas?

    You mean an external SSD? What kind of connection, that will be the bottleneck. Replacing the internal might be ok for a while till you start to fill it up, then the whole system will slow down.

  • TS3218 My iPod Nano 6th generation fell one time and it kept working with a small crack in the screen.But after a while it just gave out and does not turn on.I try to charge it and all it does is blink the apple icon on and off.When disconnected nothing h

    My iPod Nano 6th generation fell one time and it kept working with a small crack in the screen.But after a while it just gave out and does not turn on.I try to charge it and all it does is blink the apple icon on and off.When disconnected nothing happens.

    I am having the identical trouble as described above with my month old Macbook Air. I tried everything with the ditto results. Please help anyone!
    Mine is a Macbook Air 13', 128GB, 1.86GHz with 4 GB RAM.

  • Has anyone had trouble with dropped calls after downloading the IOS 7

    has anyone had trouble with dropped calls after downloading the IOS 7

    I downloaded mountain lion and then iPhoto '11 in order to tap into iCloud capabilities with all of my devices. (My Mac was outdated in regards to operating platform to do this). After installing iPhoto 11, I had to repair and rebuild my library of photos.  However, after doing this, all of my albums were jumbled and, while I can see the image thumbnail, when I click on the thumbnail, and error that looks like a black triangle and gray exclamation pops up as opposed to the larger hi def image I want to view.

Maybe you are looking for