Solved

Automate getting file share info such as name and used/free space for all servers in a domain

Posted on 2016-08-18
4
33 Views
1 Endorsement
Last Modified: 2016-09-24
Anyone have any suggestions on how to do this? I've looked into using Powershell but most servers are older and the Get-SMBShare command doesn't work. Also I tried using WMI with powershell but didn't have any luck.  I have access to SCOM and SCCM if needed, but I've never really used them before. Also, is it possible to email a report weekly?
1
Comment
Question by:Blake Fletcher
4 Comments
 
LVL 23

Accepted Solution

by:
NVIT earned 168 total points
ID: 41761460
For free space, I use wmi in a .bat file.

Make ServerNames.txt. In it put server names. e.g.:
server1
server2

Open in new window



Make FindSpace.bat. This sends results to FindSpace_WMIC.txt:
@echo off
setlocal
set FNStns=ServerNames.txt
set FNWMICOutput=%~n0_WMIC.txt
if exist "%FNWMICOutput%" del "%FNWMICOutput%"
wmic /output:"%FNWMICOutput%" /node:@"%FNStns%" logicaldisk where DriveType="3" get caption,VolumeName,VolumeSerialNumber,Size,FileSystem,FreeSpace /format:csv

Open in new window


You can run this .bat as a weekly scheduled task.

For emailing, I use the free mailer BLAT www.blat.net
Once you've confirmed the wmic code works, add this to the .bat:

set to=-to yourname@domain.com
set from=-f yourname@domain.com
set subject=-s "Server free space"
set body=-body "See "%FNWMICOutput%" for more info"
set attach=-attacht "%FNWMICOutput%"
blat %from% %mailsvr% %to% %subject% %body% %attach%

Open in new window

1
 
LVL 17

Assisted Solution

by:Mike T
Mike T earned 166 total points
ID: 41762437
Hi,

You have several options;

SCOM - requires you to create a rule to check for disk space as last time I looked it did not come with one out of the box

SCCM - runs hardware inventory, which updates every 7 days, so you should already have the data
there is a report you can run that provides that and more called

Computers with low free disk space (< % free)

which is the nearest fit. Otherwise you have to create your own report. Note with SCCM you can create a Subscription which will then email a file as XML,CSV,HTML,PDf or Excel on a schedule.

PowerShell/VBscript/Bat - as above but they will all use WMI to read the info. Even SCCM & SCOM will use the WMI anyway. That's what it's for.


Mike
  all scripts
1
 
LVL 7

Assisted Solution

by:Senior IT System Engineer
Senior IT System Engineer earned 166 total points
ID: 41775737
Hi Blake,

What about the Powershell to get all Hard drive size for some servers type or in a special OU ?

would that be useful for you ?

Save the below as .BAT file and then run scheduled tasks to run every X amount of time according to your need:

@PowerShell.exe -ExecutionPolicy RemoteSigned -Command "Invoke-Expression -Command ((Get-Content -Path '%~f0' | Select-Object -Skip 2) -join [environment]::NewLine)"
@exit /b %Errorlevel%

Clear-Host
# Issue warning if % free disk space is less
$percentWarning = 5;
# Get server list
$servers =  Get-ADComputer -Properties Name  -Filter {Enabled -eq $True -and OperatingSystem -like "*Windows Server*"} -SearchBase "OU=Servers,DC=domain,DC=com" |
	        Where-Object {Test-Connection $_.Name -Count 1 -Quiet} |
	        Where-Object { (Get-WmiObject -Class Win32_BIOS -ComputerName $_.Name ).SerialNumber -notlike "VMware*"} |
	        Select-Object -ExpandProperty Name

$datetime = (Get-Date).ToString()
 
# How many servers
$server_count = $servers.Length;
# processed server count
$i = 0;
 
foreach($server in $servers) {
	$server_progress = [int][Math]::Ceiling((($i / $server_count) * 100))
	# Parent progress bar
	Write-Progress -Activity "Checking $server" -PercentComplete $server_progress -Status "Processing servers - $server_progress%" -Id 1;
	Sleep(1); # Sleeping just for progress bar
	# Get fixed drive info
	$disks = Get-WmiObject -ComputerName $server -Class Win32_LogicalDisk -Filter "DriveType = 3";
	
 	# How many disks are there?
	$disk_count = $disks.Length;
 
 	$x = 0; 
	foreach($disk in $disks) {
		$disk_progress = [int][Math]::Ceiling((($x / $disk_count) * 100));
		$disk_name = $disk.Name;
		$volumename = $disk.VolumeName;
		Write-Progress -Activity "Checking disk $disk_name" -PercentComplete $disk_progress -Status "Processing server disks - $disk_progress%" -Id 2;
		Sleep(1);
		$deviceID = $disk.DeviceID; 
		[float]$size = $disk.Size;
		[float]$freespace = $disk.FreeSpace;
 
		$percentFree = [Math]::Round(($freespace / $size) * 100, 2);
		$sizeGB = [Math]::Round($size / 1073741824, 2);
		$freeSpaceGB = [Math]::Round($freespace / 1073741824, 2);
 		$usedGB = $sizeGB - $freeSpaceGB
		
		$colour = "Green";
		if($percentFree -lt $percentWarning) {
			$colour = "Red";
            $mailsubject = "Disk space low on " + $server + " - " + "$deviceID drive" +  " - free space ($freeSpaceGB GB)" + " - percentage free space = $percentFree %"
			$mailbody = "$server $deviceID - disk size - $volumename ($sizeGB GB), used space ($usedGB GB), free space ($freeSpaceGB GB), percentage free space = $percentFree %, as at $datetime"
            Send-MailMessage -Body $mailbody -To username@domain.com -From SystemAdmin@domain.com -SmtpServer smtp.domain.com -Subject $mailsubject
		}
		
		if ( $volumename -eq "" ) {
			$volumename = "*"
		}
		
		Write-Host -ForegroundColor $colour "$server $deviceID - disk size - $volumename ($sizeGB GB), used space ($usedGB GB), free space ($freeSpaceGB GB), percentage free space = $percentFree %";
		$x++;
	}
	# Finish off the progress bar
	Write-Progress -Activity "Finished checking disks for this server" -PercentComplete 100 -Status "Done - 100%" -Id 2;
	Sleep(1); # Just so we see some progress!
	$i++;
	Write-Host ""
}
Write-Progress -Activity "Checked all servers" -PercentComplete 100 -Status "Done - 100%" -Id 1;
Sleep(1);

Open in new window


it will send out email per server based on certain threshold limit, in this case is 5% empty disk space.
0
 
LVL 34

Expert Comment

by:Seth Simmons
ID: 41813557
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Split:
-- NVIT (https:#a41761460)
-- Mike T (https:#a41762437)
-- ITSystemEngineer (https:#a41775737)


If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

seth2740
Experts-Exchange Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help you understand what HashTables are and how to use them in PowerShell.
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

920 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

16 Experts available now in Live!

Get 1:1 Help Now