- 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 .

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

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 .
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