Check diskspace

May 06, 2020 15:47



function Check-FreeSpace {
<#
  .SYNOPSIS
  Описание функции
  .DESCRIPTION
  Более подробное описание функции
  .EXAMPLE
    Check-FreeSpace -computername comp1 -percent 10
  .EXAMPLE
    Check-FreeSpace
  .PARAMETER computername
  Имя запрашиваемого компьютера.
  #>
[CmdletBinding()]
param
(
  [Parameter(Mandatory=$false,
  ValueFromPipeline=$True,
  HelpMessage='По умолчанию будет использовано значение localhost и порог срабатывания 20%')]
  [ValidateLength(3,30)]
  [string[]]$computername = 'localhost',

[validateLength(2,2)]
  [string[]]$Letter = 'C:',

[ValidateRange(1,99)]
  [int]$percent = 20
)

begin {}

process {

foreach ($computer in $computername) {
    Write-Verbose "Processing $computer $disk"
    #$drive=Get-WMIObject Win32_Logicaldisk -filter $f -ComputerName $computer
    $drive = Get-CimInstance -ComputerName $Computer -ClassName CIM_LogicalDisk | Where-Object {$_.DeviceID -eq $Letter}
    $WarningLevel=$drive.Size * ($Percent/100)
    #Write-Verbose $WarningLevel
    Write-Verbose $drive.freespace
    if ($drive.freespace -lt $WarningLevel) {return $True}
    else {return $false}
    }
  }
end {}
}

diskspace, powershell, #write

Previous post Next post
Up