简体   繁体   English

如何使用Powershell从Active Directory上的计算机获取磁盘信息

[英]How to get disk information from computers on Active Directory with Powershell

我具有PowerShell的基本知识,并且得到了一个项目,该项目需要我创建一个PowerShell脚本,该脚本将域中的所有计算机都放在活动目录中,并收集每台计算机的可用空间/已用空间。

This is what I use in order to get servers with low disk space: 这是我用来获取磁盘空间不足的服务器的方法:

Import-Module ActiveDirectory

$Servers = Get-ADcomputer -Filter {OperatingSystem -like "*Server*"} -Properties Name, OperatingSystem -SearchBase "DC=yourDN,DC=local" | Select Name
$diskReport = Foreach($Server in $Servers)
{

    #$Status = "Offline"    
    $Name = $Server.Name
    #Make sure server is online
    if(Test-Connection -ComputerName $Name -ErrorAction SilentlyContinue)
    {

        #Get only 10%       
        Get-WMIObject win32_logicaldisk -ComputerName $Name -Filter "DriveType=3" -ErrorAction SilentlyContinue | Where-Object {   ($_.freespace/$_.size) -le '0.1'}        
    }
    else
    {
        #Server is offline
    }       

}

$lowservers = $diskreport | Select-Object @{Label = "Server Name";Expression = {$_.SystemName}},
        @{Label = "Drive Letter";Expression = {$_.DeviceID}},
        @{Label = "Total Capacity (GB)";Expression = {"{0:N1}" -f( $_.Size / 1gb)}},
        @{Label = "Free Space (GB)";Expression = {"{0:N1}" -f( $_.Freespace / 1gb ) }},
        @{Label = 'Free Space (%)'; Expression = {"{0:P0}" -f ($_.freespace/$_.size)}} 

This will first pull all your objects using Get-ADComputer. 这将首先使用Get-ADComputer拉动所有对象。 Then it just does a simple foreach to put everything into $diskReport. 然后,它将所有内容放入$ diskReport只是一个简单的foreach。 The $lowservers is just to clean it up a bit. $ lowservers只是要清理一点。

You can do whatever you want with $lowservers. 您可以使用$ lowservers做任何您想做的事情。 I have mine on a scheduled task to run every Monday and Friday. 我有一个预定的任务,每个星期一和星期五运行。 Then send out an email if it finds something low. 如果发现不足,请发送电子邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Active Directory:如何获取属于另一个域的组信息? - Active Directory : How to get Group information that belongs to another domain? 如何使用用户列表编写带有 For 循环的 Powershell 脚本以打印出 Active Directory 信息 - How to write a Powershell Script with a For-loop using a List of Users to Print Out Active Directory Information 尝试使用Powershell在活动目录中的OU中查找计算机,以查看它们是否为特定软件 - trying to use Powershell to look in an OU in active directory for computers to see if they specific software 从Windows Active Directory查询信息 - Querying information from the Windows Active Directory 如何在c中获取硬盘信息? - how to get hard disk information in c? Active Directory和Powershell - Active Directory and Powershell 如何在磁盘上获取确切的目录大小 - How to get exact directory size on disk Powershell - 如何显示列表中的哪些计算机正在运行特定进程? - Powershell - how to show which computers from a list are running a specific process? 如何从Active Directory获取用户密码的到期日期? - How to get user password expiration date from Active Directory? Windows 2008 服务器 Powershell Active Directory -> 获取用户创建日期 - Windows 2008 server Powershell Active Directory -> Get user creation date
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM