Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
49 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 25

Accepted Solution

by:
NVIT earned 672 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 18

Assisted Solution

by:Mike T
Mike T earned 664 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 8

Assisted Solution

by:Senior IT System Engineer
Senior IT System Engineer earned 664 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 35

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Windows Server 2003 introduced persistent Volume Shadow Copies and made 2003 a must-do upgrade.  Since then, it's been a must-implement feature for all servers doing any kind of file sharing.
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

721 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