powershell script for finding the total memory space of c driveEcho equivalent in PowerShell for script testingTerminating a script in PowerShellHow to run a PowerShell scriptPowerShell says “execution of scripts is disabled on this system.”What's the best way to determine the location of the current PowerShell script?How to pass an argument to a PowerShell script?List physical drive spaceColor-code cells in HTML mail based on criteriaPowershell progress bar vertical spacepowershell bitlocker won't unlock drive properly
Dropping outliers based on "2.5 times the RMSE"
Why the term 'unified' in "unified mass unit"?
As a DM, how to avoid unconscious metagaming when dealing with a high AC character?
What is the English equivalent of 干物女 (dried fish woman)?
How does one stock fund's charge of 1% more in operating expenses than another fund lower expected returns by 10%?
Modeling, view and projection transformation using vector and point in homogenous form
Can I play a first turn Simic Growth Chamber to have 3 mana available in the second turn?
download the bitcoin chain begining from a certain date
Help with understanding nuances of extremely popular Kyoto-ben (?) tweet
Why would an Inquisitive rogue choose to use Insightful Fighting as opposed to using their Cunning Action to Hide?
Supporting developers who insist on using their pet language
Is purchasing foreign currency before going abroad a losing proposition?
Is `curl something | sudo bash -` a reasonably safe installation method?
School House Points (Python + SQLite)
Hacker Rank : Electronics Shop
How to check the quality of an audio sample?
Why does java.time.Period#normalized() not normalize days?
Chaining Dissonant Whispers via War Caster feat
What to put after taking off rear stabilisers from child bicyle?
Does Google Maps take into account hills/inclines for route times?
A DVR algebra with weird automorphisms
Filtering fine silt/mud from water (not necessarily bacteria etc.)
Should you avoid redundant information after dialogue?
Find values of x so that the matrix is invertible
powershell script for finding the total memory space of c drive
Echo equivalent in PowerShell for script testingTerminating a script in PowerShellHow to run a PowerShell scriptPowerShell says “execution of scripts is disabled on this system.”What's the best way to determine the location of the current PowerShell script?How to pass an argument to a PowerShell script?List physical drive spaceColor-code cells in HTML mail based on criteriaPowershell progress bar vertical spacepowershell bitlocker won't unlock drive properly
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want a PowerShell script to get the total memory space of C drive and used memory space in GB, if the total space is less than 200 GB it should print disk space is less than 200.
gwmi win32_logicaldisk | Format-Table DeviceId, MediaType, @n="Size";e=[math]::Round($_.Size/1GB,2),@n="FreeSpace";e=[math]::Round($_.FreeSpace/1GB,2)
$task=gwmi win32_logicaldisk | Format-Table DeviceId, MediaType, @n="Size";e=[math]::Round($_.Size/1GB,2),@n="FreeSpace";e=[math]::Round($_.FreeSpace/1GB,2)
if($task.Size -lt 200)
Write-Host "Hard Disk Space is less than 200."
else
Write-Host "Hard Disk Space is greater than 200."
I am getting all drive space on the above code, I need only C drive information and if condition is not working properly,Some one help me through this. Thanks in advance
powershell
add a comment |
I want a PowerShell script to get the total memory space of C drive and used memory space in GB, if the total space is less than 200 GB it should print disk space is less than 200.
gwmi win32_logicaldisk | Format-Table DeviceId, MediaType, @n="Size";e=[math]::Round($_.Size/1GB,2),@n="FreeSpace";e=[math]::Round($_.FreeSpace/1GB,2)
$task=gwmi win32_logicaldisk | Format-Table DeviceId, MediaType, @n="Size";e=[math]::Round($_.Size/1GB,2),@n="FreeSpace";e=[math]::Round($_.FreeSpace/1GB,2)
if($task.Size -lt 200)
Write-Host "Hard Disk Space is less than 200."
else
Write-Host "Hard Disk Space is greater than 200."
I am getting all drive space on the above code, I need only C drive information and if condition is not working properly,Some one help me through this. Thanks in advance
powershell
add a comment |
I want a PowerShell script to get the total memory space of C drive and used memory space in GB, if the total space is less than 200 GB it should print disk space is less than 200.
gwmi win32_logicaldisk | Format-Table DeviceId, MediaType, @n="Size";e=[math]::Round($_.Size/1GB,2),@n="FreeSpace";e=[math]::Round($_.FreeSpace/1GB,2)
$task=gwmi win32_logicaldisk | Format-Table DeviceId, MediaType, @n="Size";e=[math]::Round($_.Size/1GB,2),@n="FreeSpace";e=[math]::Round($_.FreeSpace/1GB,2)
if($task.Size -lt 200)
Write-Host "Hard Disk Space is less than 200."
else
Write-Host "Hard Disk Space is greater than 200."
I am getting all drive space on the above code, I need only C drive information and if condition is not working properly,Some one help me through this. Thanks in advance
powershell
I want a PowerShell script to get the total memory space of C drive and used memory space in GB, if the total space is less than 200 GB it should print disk space is less than 200.
gwmi win32_logicaldisk | Format-Table DeviceId, MediaType, @n="Size";e=[math]::Round($_.Size/1GB,2),@n="FreeSpace";e=[math]::Round($_.FreeSpace/1GB,2)
$task=gwmi win32_logicaldisk | Format-Table DeviceId, MediaType, @n="Size";e=[math]::Round($_.Size/1GB,2),@n="FreeSpace";e=[math]::Round($_.FreeSpace/1GB,2)
if($task.Size -lt 200)
Write-Host "Hard Disk Space is less than 200."
else
Write-Host "Hard Disk Space is greater than 200."
I am getting all drive space on the above code, I need only C drive information and if condition is not working properly,Some one help me through this. Thanks in advance
powershell
powershell
edited Mar 26 at 5:44
Vivek Kumar Singh
2,3231 gold badge9 silver badges18 bronze badges
2,3231 gold badge9 silver badges18 bronze badges
asked Mar 26 at 5:43
Ashwin KumarAshwin Kumar
113 bronze badges
113 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can use the Get-Volume cmdlet -
if (((Get-Volume -DriveLetter C).Size)/1GB -lt 200)
Write-Host "Hard Disk Space is less than 200."
else
Write-Host "Hard Disk Space is greater than 200."
add a comment |
if you need to run this test on win7 - even with ps5.1 - you can't use the Get-Volume
cmdlet. [sigh ...] so here is one that uses CMI/WMI for that.
what it does ...
- sets a min free space threshold
- uses the faster, non-deprecated CIM stuff to get the info on drive C:
- only returns info if the C: drive meets the min freespace requirement
- uses
[string]::IsNullOrEmpty()
to see if the result has any info in it - then uses an IF structure to decide what message to show
- if space is too low, it uses the
Write-Warning
cmdlet for the nice orange text [grin]
here's the code ...
$MinFreeSpace_GB = 800
$CDriveMinFree = [string]::IsNullOrEmpty((Get-CimInstance -ClassName CIM_LogicalDisk |
Where-Object
$_.DeviceID -eq 'C:' -and
$_.FreeSpace -lt $MinFreeSpace_GB * 1GB
))
if ($CDriveMinFree)
'The C: drive has at least 0 GB free.' -f $MinFreeSpace_GB
else
Write-Warning ('Low free space on Drive C:!')
output on my 600 GB free C: drive with the test threshold set to 800 ...
WARNING: Low free space on Drive C:!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350528%2fpowershell-script-for-finding-the-total-memory-space-of-c-drive%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the Get-Volume cmdlet -
if (((Get-Volume -DriveLetter C).Size)/1GB -lt 200)
Write-Host "Hard Disk Space is less than 200."
else
Write-Host "Hard Disk Space is greater than 200."
add a comment |
You can use the Get-Volume cmdlet -
if (((Get-Volume -DriveLetter C).Size)/1GB -lt 200)
Write-Host "Hard Disk Space is less than 200."
else
Write-Host "Hard Disk Space is greater than 200."
add a comment |
You can use the Get-Volume cmdlet -
if (((Get-Volume -DriveLetter C).Size)/1GB -lt 200)
Write-Host "Hard Disk Space is less than 200."
else
Write-Host "Hard Disk Space is greater than 200."
You can use the Get-Volume cmdlet -
if (((Get-Volume -DriveLetter C).Size)/1GB -lt 200)
Write-Host "Hard Disk Space is less than 200."
else
Write-Host "Hard Disk Space is greater than 200."
answered Mar 26 at 5:52
Vivek Kumar SinghVivek Kumar Singh
2,3231 gold badge9 silver badges18 bronze badges
2,3231 gold badge9 silver badges18 bronze badges
add a comment |
add a comment |
if you need to run this test on win7 - even with ps5.1 - you can't use the Get-Volume
cmdlet. [sigh ...] so here is one that uses CMI/WMI for that.
what it does ...
- sets a min free space threshold
- uses the faster, non-deprecated CIM stuff to get the info on drive C:
- only returns info if the C: drive meets the min freespace requirement
- uses
[string]::IsNullOrEmpty()
to see if the result has any info in it - then uses an IF structure to decide what message to show
- if space is too low, it uses the
Write-Warning
cmdlet for the nice orange text [grin]
here's the code ...
$MinFreeSpace_GB = 800
$CDriveMinFree = [string]::IsNullOrEmpty((Get-CimInstance -ClassName CIM_LogicalDisk |
Where-Object
$_.DeviceID -eq 'C:' -and
$_.FreeSpace -lt $MinFreeSpace_GB * 1GB
))
if ($CDriveMinFree)
'The C: drive has at least 0 GB free.' -f $MinFreeSpace_GB
else
Write-Warning ('Low free space on Drive C:!')
output on my 600 GB free C: drive with the test threshold set to 800 ...
WARNING: Low free space on Drive C:!
add a comment |
if you need to run this test on win7 - even with ps5.1 - you can't use the Get-Volume
cmdlet. [sigh ...] so here is one that uses CMI/WMI for that.
what it does ...
- sets a min free space threshold
- uses the faster, non-deprecated CIM stuff to get the info on drive C:
- only returns info if the C: drive meets the min freespace requirement
- uses
[string]::IsNullOrEmpty()
to see if the result has any info in it - then uses an IF structure to decide what message to show
- if space is too low, it uses the
Write-Warning
cmdlet for the nice orange text [grin]
here's the code ...
$MinFreeSpace_GB = 800
$CDriveMinFree = [string]::IsNullOrEmpty((Get-CimInstance -ClassName CIM_LogicalDisk |
Where-Object
$_.DeviceID -eq 'C:' -and
$_.FreeSpace -lt $MinFreeSpace_GB * 1GB
))
if ($CDriveMinFree)
'The C: drive has at least 0 GB free.' -f $MinFreeSpace_GB
else
Write-Warning ('Low free space on Drive C:!')
output on my 600 GB free C: drive with the test threshold set to 800 ...
WARNING: Low free space on Drive C:!
add a comment |
if you need to run this test on win7 - even with ps5.1 - you can't use the Get-Volume
cmdlet. [sigh ...] so here is one that uses CMI/WMI for that.
what it does ...
- sets a min free space threshold
- uses the faster, non-deprecated CIM stuff to get the info on drive C:
- only returns info if the C: drive meets the min freespace requirement
- uses
[string]::IsNullOrEmpty()
to see if the result has any info in it - then uses an IF structure to decide what message to show
- if space is too low, it uses the
Write-Warning
cmdlet for the nice orange text [grin]
here's the code ...
$MinFreeSpace_GB = 800
$CDriveMinFree = [string]::IsNullOrEmpty((Get-CimInstance -ClassName CIM_LogicalDisk |
Where-Object
$_.DeviceID -eq 'C:' -and
$_.FreeSpace -lt $MinFreeSpace_GB * 1GB
))
if ($CDriveMinFree)
'The C: drive has at least 0 GB free.' -f $MinFreeSpace_GB
else
Write-Warning ('Low free space on Drive C:!')
output on my 600 GB free C: drive with the test threshold set to 800 ...
WARNING: Low free space on Drive C:!
if you need to run this test on win7 - even with ps5.1 - you can't use the Get-Volume
cmdlet. [sigh ...] so here is one that uses CMI/WMI for that.
what it does ...
- sets a min free space threshold
- uses the faster, non-deprecated CIM stuff to get the info on drive C:
- only returns info if the C: drive meets the min freespace requirement
- uses
[string]::IsNullOrEmpty()
to see if the result has any info in it - then uses an IF structure to decide what message to show
- if space is too low, it uses the
Write-Warning
cmdlet for the nice orange text [grin]
here's the code ...
$MinFreeSpace_GB = 800
$CDriveMinFree = [string]::IsNullOrEmpty((Get-CimInstance -ClassName CIM_LogicalDisk |
Where-Object
$_.DeviceID -eq 'C:' -and
$_.FreeSpace -lt $MinFreeSpace_GB * 1GB
))
if ($CDriveMinFree)
'The C: drive has at least 0 GB free.' -f $MinFreeSpace_GB
else
Write-Warning ('Low free space on Drive C:!')
output on my 600 GB free C: drive with the test threshold set to 800 ...
WARNING: Low free space on Drive C:!
answered Mar 26 at 6:09
Lee_DaileyLee_Dailey
3,6582 gold badges8 silver badges12 bronze badges
3,6582 gold badges8 silver badges12 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350528%2fpowershell-script-for-finding-the-total-memory-space-of-c-drive%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown