Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

SOLVED Total and Free disk space -servers/workstations

  • Thread starter Thread starter Gokul
  • Start date Start date
  • Replies Replies 2
  • Views Views 22K
Status
Not open for further replies.

Gokul

Well-Known Member
Staff member
Messages
321
Solutions
4
Reaction score
58
Points
28
Good Day All

Being working on sccm we have to get the details of some of server / workstation as per our daily task or customer requirement . Here i am introducing easiest way to get the Total and Free disk space -servers/workstations using PS script .

SS 1.JPG
Create one text file "InputServerNames" in one drive like mentioned above(create one folder and keep the things under folder). So we will add servers to this and script take the data from here. Results will be stored as Results.csv and logs will get generated (details.log). log and csv file will be created by scripts
.Attaching the Script . Save the script as .ps1 format in the same folder

SCRIPT

#----------------------------------------------------------------------------------------#

#This script will run on given servers/workstations and will find out its Total and Free disk space
$scriptdir = Split-Path $Script:MyInvocation.mycommand.path
$Computers = Get-Content $scriptdir\"InputServerNames.txt"
$date = Get-Date -Format "dd-MM-yyyy hh:mm:ss"
$log = "$scriptdir\details.log"
Remove-Item $scriptdir\"Results.csv" -Recurse
Foreach($computer in $Computers)
{
try
{
"$date [Info]`t Getting Disk space information from $Computer" | Out-File -Append $log
Get-WmiObject win32_Logicaldisk -ComputerName $computer | Select @{n='Computer Name';e={$_.pscomputername}},@{n='Drive Letter';e={$_.caption}},@{n='Total Size';e={[math]::round($_.size/1GB, 2)}},@{n='Free Space';e={[math]::Round($_.FreeSpace/1GB, 2)}} | Export-csv -Append $scriptdir\"Results.csv" -NoTypeInformation
"$date [Info]`t Copied Disk space information of $Computer to Results.csv file" | Out-File -Append $log
}
catch
{
"[ERROR]`t Unable to connect to WMI of $Computer" | Out-File -Append $log
}
}
#----------------------------------------------------------------------------------------

RESULT


SS 1.JPG
 
While I love PowerShell, the "connectivity required" component of this can cause data gaps. You could do this using a CM Query if you're capturing the Logical_Disk attribute:

select SMS_R_System.Name,
SMS_G_System_LOGICAL_Disk.Name,
SMS_G_System_LOGICAL_Disk.VolumeName,
SMS_G_System_LOGICAL_Disk.FreeSpace,
SMS_G_System_LOGICAL_Disk.Size from SMS_R_System inner join
SMS_G_System_LOGICAL_Disk on
SMS_G_System_LOGICAL_Disk.ResourceID =
SMS_R_System.ResourceID where
SMS_G_System_LOGICAL_Disk.VolumeName like "%" order by
SMS_R_System.Name,
SMS_G_System_LOGICAL_Disk..VolumeName

It'd run faster than a script that's connecting to all the clients and you can quickly copy/paste the results to the format you desire. You can even add a column for last seen if you're concerned about stale data.

On a personal note, anything worth scripting that produces CSV output is usually worth invoking a COM__ instance of Excel and generating some nice workbooks. :)
 
@Sam Banford , thanks for sharing this. In my cause I used to save the scrip in drive with a notepad. So that my colleagues can use the script just simply adding the machines to notepad and running the script. I appreciate your information
 
Status
Not open for further replies.

Forum statistics

Threads
7,133
Messages
27,858
Members
18,151
Latest member
TonyGTR
Back
Top