SOLVED Total and Free disk space -servers/workstations

Status
Not open for further replies.

Gokul

Well-Known Member
Staff member
321
55
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
 
  • Like
Reactions: Aswathy Raj

Sam Banford

Well-Known Member
163
21
18
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. :)
 
OP
Gokul

Gokul

Well-Known Member
Staff member
321
55
28
@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
4,514
Messages
17,668
Members
9,104
Latest member
KoreBreach