Author Posts

April 23, 2018 at 2:59 pm

[CmdletBinding()]
param()
Begin
{

$Totalmemory = (Get-WmiObject -Class Win32_operatingsystem).TotalVisibleMemorySize
#Get Live Memory Status
$FreeMem = ((Get-Counter -Counter "\memory\available mbytes" -MaxSamples 2 -SampleInterval 2 ).CounterSamples).CookedValue
$FinalFreemem = ((($FreeMem | Measure-Object -Minimum).Minimum)/1024).Tostring("#.###")
$meminGB = ($Totalmemory/1024) 
$FinalTotalmem = ($meminGB/1024).ToString("##.###")
$TotalFreeMemPerc = ($FinalFreemem/$FinalTotalmem)*100
}
Process
{
while($true)
{

if ($TotalFreeMemPerc -le 20)

{
    $TotalFreeMemPerc
    $Bindtest= 1..3 | % {(Test-NetConnection -ComputerName ("$env:COMPUTERNAME"+"."+"$env:USERDNSDOMAIN") -Port 636).TcpTestSucceeded}
    
    $Bindtest
    
if ($Bindtest -notcontains $false)
    {
    Write-Verbose -Message "Bind Successful"
    }
Else
    {
                    
    Write-Error "very bad"
   }}}}
    End
    {
    
    }

April 23, 2018 at 3:01 pm

Could you please format your code as code? And what is your question?

April 23, 2018 at 3:06 pm

Formatted that code & Memory is not changing while running . need to capture the live memory data.

April 23, 2018 at 3:57 pm

$FreeMem is defined outside the loop, and never redefined. You are retrieving only the current value data from the sample at one point, and never accessing the counter again.

April 24, 2018 at 9:22 am

Thanks. Now that is working.