powershell 获取从Active Directory读取的远程计算机的磁盘空间详细信息。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 获取从Active Directory读取的远程计算机的磁盘空间详细信息。相关的知识,希望对你有一定的参考价值。

<#
    .Synopsis
        Get the disk space details of remote computers read from Active Directory.
       
    .Description
        This script helps you to get the disk space details of local disks and removable disks of
                remote computers using powershell. It will also get the space details of mount points.
 
    .Parameter SearchBase
        The Active Directory OU to search for computers to view disk details on.
       
    .Example
        Get-DiskSpaceDetails.ps1 -SearchBase "OU=Faculty Tablets,OU=LSHS Computers,DC=lshs,DC=org"
               
                Get the total disk space, free disk space, and percentage disk free space details of computers in AD OU.
       
    .Example
        Get-DiskSpaceDetails.ps1 -SearchBase "OU=Faculty Tablets,OU=LSHS Computers,DC=lshs,DC=org" | ? {$_."`%Freespace `(GB`)" -lt 5}
       
        Get all the drives which are having less than 5% free space.
       
 
#>
 
[cmdletbinding()]
param(
        [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$SearchBase = "OU=Faculty Tablets,OU=LSHS Computers,DC=lshs,DC=org"
       
)
 
begin {
       
}
 
process {
        $Computers = get-adcomputer -SearchBase $SearchBase -Filter "*" | Where {$_.Enabled -eq "true"}
        foreach($Computer in $Computers) {
                Write-Verbose "Working on $Computer"
                if(Test-Connection -ComputerName $Computer.Name -Count 1 -ea 0) {
                        $VolumesInfo = Get-WmiObject -ComputerName $Computer.Name -Class Win32_Volume | ? {$_.DriveType -eq 2 -or $_.DriveType -eq 3 }
                        foreach($Volume in $VolumesInfo) {
                               
                                $Capacity       = [System.Math]::Round(($Volume.Capacity/1GB),2)
                                $FreeSpace      = [System.Math]::Round(($Volume.FreeSpace/1GB),2)
                                $UsedSpace      = $Capacity - $FreeSpace
                                $PctFreeSpace   = [System.Math]::Round(($Volume.FreeSpace/$Volume.Capacity)*100,2)
                                $OutputObj      = New-Object -TypeName PSobject
                                $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.Name
                                $OutputObj | Add-Member -MemberType NoteProperty -Name DriveName -Value $Volume.Caption
                                $OutputObj | Add-Member -MemberType NoteProperty -Name DriveType -Value $Volume.DriveType
                                $OutputObj | Add-Member -MemberType NoteProperty -Name "Capacity `(GB`)" -Value $Capacity
                                $OutputObj | Add-Member -MemberType NoteProperty -Name "Used Space `(GB`)" -Value $UsedSpace
                                $OutputObj | Add-Member -MemberType NoteProperty -Name "FreeSpace `(GB`)" -Value $FreeSpace
                                $OutputObj | Add-Member -MemberType NoteProperty -Name "`%FreeSpace `(GB`)" -Value $PctFreeSpace
                                $OutputObj# | Select ComputerName, DriveName, DriveType, Capacity, FreeSpace, PctFreespace | ft -auto
                        }
                } else {
                        Write-Verbose "$Computer is not reachable"
                }
        }
}
 
end {
}

以上是关于powershell 获取从Active Directory读取的远程计算机的磁盘空间详细信息。的主要内容,如果未能解决你的问题,请参考以下文章

powershell 获取从Active Directory读取的远程计算机的磁盘空间详细信息。

powershell Active Directory获取当前的域功能

powershell 此脚本获取Active Directory组的成员

Powershell About Active Directory Server

PowerShell 操作 Azure SQL Active Geo-Replication

Active Directory 命令在 PowerShell 下工作,但不适用于命令提示符