[英]Using Powershell Get-ItemProperty through all of AD computers object
[英]Get AD Computers PowerShell
如何使用此param
在 AD 中獲取計算機,有人可以幫助我。
Param(
[string] $ComputerName = $env:computername,
[int] $NumberOfDays = 10,
[switch] $DebugInfo
)
我試過但我不冷
使用 PowerShell 獲得正常運行時間並不能很好地擴展。所以請記住,這將需要一些時間,具體取決於您的 AD 的大小。 如果您需要查詢一組特定的計算機(即特定的 OU),請使用 LDAP 過濾器。 以下鏈接中的示例 4: https://learn.microsoft.com/en-us/powershell/module/activedirectory/get-adcomputer?view=windowsserver2022-ps
這是一個基本腳本,可獲取域內所有計算機的上次啟動時間信息。
另請記住,您需要對目標 PC 具有適當的權限。
#Get all relevant computers
$Computers = Get-ADComputer -Filter *
#Declare an empty array to collect custom objects from the pipeline.
$ComputerInfoCollection = @()
#Iterate all computers an get uptime information
foreach($computer in $computers){
$UpTime = (Get-CimInstance -ComputerName $computer.name -ClassName Win32_OperatingSystem -ErrorAction SilentlyContinue ).LastBootUpTime
if(!$UpTime){
$UpTime = 'NotResolved'
}
$ComputerInfo = [PSCustomObject]@{
'Name' = $computer.Name
'Uptime' = $UpTime
}
$ComputerInfoCollection += $ComputerInfo
}
$ComputerInfoCollection
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.