Solved

Script to get the free space in differents hard disk units

Posted on 2012-03-11
6
397 Views
Last Modified: 2012-06-03
Hi guys,

I need your help. I am not able to achive it by myself, I am trying but I am having troubles.

I need to run a script to get the size of a unit and the avilable free space. The same for all units in that server.  I would like to create an .xls with the output

Example:  
server: server01

c:   20 gb   10 gb free
d:  30 gb    20 gb free
...
and so for all units


I would like to use WSH and WMI but it is not friendly for me as I would like. I am working hard to learn but I need now.

Could anyone help me?
0
Comment
Question by:projectja
  • 3
  • 3
6 Comments
 
LVL 8

Expert Comment

by:fundacionrts
Comment Utility
This script [Powershell] returns CSV file with DeviceID, Size and FreeSize of all local hard drives

Get-WMIObject Win32_LogicalDisk -Filter "DriveType=3" | Select-Object DeviceID,FreeSpace,Size | Export-Csv ./localhdd.csv
0
 

Author Comment

by:projectja
Comment Utility
Hi,

Thanks for the reply, It is interesting.

Please, let me explain better.

I would need a powershell such as:

- It will be launch from  my workstation or server of my domain providing administrattors credential in other domains to be able to execute command there.
- The goal is to get:
* To get information about differents hard disk units on target server; total space in disk and free space available. (could have c,d,e,...) units. There is not a rule.
* Export that information to excel, creating the file iin the pc where the scrilpt is being launching (source pc in which I am launching the script). The name of the file is the same that the IP adress of the server where we are connecting to get information.
* In a specific folder on the target server check for files which are  contained into a specific folder and are two weeks old, the goal is delete them (are logs files). report the action in a logs indicating amount of deleted files and the size disk.

Please, I need the help of an expert, It is very important for me to be able to finish this task.


*
0
 
LVL 8

Expert Comment

by:fundacionrts
Comment Utility
## This scripts generate 2 output files
## remoteip.csv - CSV file that includes all logical drivers of a computer with free space and total size
## remoteip.log - Log file that includes all files remove from remote folder that have more than 15 days (last write access)

#
# Constants
#

#$pathoutputfiles ALWAYS ends with \
$pathoutputfiles = "c:\path\to\output\files\"

#
# Read parameters
#

Write-Host "Enter remote computer IP (Format: xxx.xxx.xxx.xxx) ..."
$remoteip = Read-Host
Write-Host "Enter credentials for remote computer connection (Format: domain\username)..."
$credential = Get-Credential
Write-Host "Enter remote folder to scan (Format: \\server\path\) ..."
$remotefolder = Read-Host

#
# Get Hard Disk stats
#

Get-WMIObject Win32_LogicalDisk -Filter "DriveType=3" | Select-Object DeviceID,FreeSpace,Size | Export-Csv "$pathoutputfiles$remoteip.csv"

#
# Scan remote logs files
#
$stream = [System.IO.StreamWriter] "$pathoutputfiles$remoteip.log"
$files = Get-ChildItem -Path "$remotefolder" | Where-Object {$_.LastWriteTime -le [System.DateTime]::Now.AddDays(-15)}
foreach ($file in $files) {
    if ($File -ne $NULL) {
            Write-Host "Deleting File $File"
            $stream.WriteLine("Deleting File $File")
            Remove-Item $File.FullName | Out-Null
      }
}
$stream.close()
0
Too many email signature updates to deal with?

Do you feel like you are taking up all of your time constantly visiting users’ desks to make changes to email signatures? Wish you could manage all signatures from one central location, easily design them and deploy them quickly to users? Well, there is an easy way!

 

Author Comment

by:projectja
Comment Utility
Sorry for the dalay.

I have been working, but I happily saw your reply.
It is very intesting. Now, I am working to prepare it.
With regard to the .XLS file, I would like to add the day date so I have modified in this way:

#==================================r======
#==========================================
$fechadeHoy = [System.DateTime]::Now

$day=$fechadehoy.day.ToString()
$month = $fechadehoy.month.ToString()
$year= $fechadehoy.year.Tostring()


$stream = [System.IO.StreamWriter] "$pathoutputfiles$remoteip$day$month$year.log"

Issues:

- I get "month" = 3,  I want "03"

Any advice?
0
 
LVL 8

Accepted Solution

by:
fundacionrts earned 500 total points
Comment Utility
$day=$fechadehoy.ToString("dd")
$month = $fechadehoy.ToString("MM")
$year= $fechadehoy.Tostring("yyyy")
0
 

Author Comment

by:projectja
Comment Utility
Thank you very much. Is has been very useful
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now