Abra o o PowerShell ISE, com uma conta que tenha permissão de leitura no Active Directory e permissão de administrador nos desktops. Coloque o seguinte código, alterando a parte em cinza pelo distinguished name da unidade organizacional que você deseja (caso não saiba Como obter o distinguished name, leia nosso Post sobre esse assunto):
#———————————————————————————–
$SEARCH_OU=”OU=Nome_da_OU,DC=seu_dominio,DC=com,DC=br“
#———————————————————————————–
$ErrorActionPreference= ‘silentlycontinue’
$Sleep=10
$namespace = “root\CIMV2”
$DaysInactive = 90
$time = (Get-Date).Adddays(-($DaysInactive))
#Criando a variável em branco
$KeysArray = @()
Clear-host
Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -Searchbase $SEARCH_OU | ForEach-Object {
$Name = “localhost”
$Name = $_.Name
write-host “PC: $Name” -NoNewline
If (Test-Connection -ComputerName $Name -Count 1 -ErrorAction SilentlyContinue)
{
$Processor = gwmi win32_processor -ComputerName $Name | Select Name,LoadPercentage
$ProcessorName = $Processor.Name
$ProcessorName = $ProcessorName.Split(” “)[2]
$ProcessorName = $ProcessorName.Replace(“Intel(R) Core(TM)”,””).Replace(“CPU”,””).Replace(” “,””).Split(“@”)[0]
$ProcessorLoadPercentage = $Processor.LoadPercentage
#— EQUIPAMENTO —
$Serialnumber = gwmi win32_bios -ComputerName $Name | select serialnumber
$Manufacturer = gwmi win32_bios -ComputerName $Name | select version
#— DISCO(S) —
$Disks = gwmi Win32_diskdrive -ComputerName $Name | select model
$DiskModels = $Disks.model -join “;”
$Idle1=$DiskTime1=$T1=$Idle2=$DiskTime2=$T2=1
$Disk = Get-WmiObject -class Win32_PerfRawData_PerfDisk_LogicalDisk -filter “name= ‘C:'”
[Double]$Idle1 = $Disk.PercentIdleTime
[Double]$DiskTime1 = $Disk.PercentDiskTime
[Double]$T1 = $Disk.TimeStamp_Sys100NS
start-Sleep $Sleep
$Disk = Get-WmiObject -class Win32_PerfRawData_PerfDisk_LogicalDisk -filter “name= ‘C:’ “
[Double]$Idle2 = $Disk.PercentIdleTime
[Double]$DiskTime2 = $Disk.PercentDiskTime
[Double]$T2 = $Disk.TimeStamp_Sys100NS
$PercentIdleTime = [math]::Round((($Idle2 – $Idle1) / ($T2 – $T1)) * 100)
$PercentDiskTime = [math]::Round((($DiskTime2 – $DiskTime1) / ($T2 – $T1)) * 100)
#— MEMORIA —
$memory = gwmi win32_operatingsystem -ComputerName $Name | select TotalVisibleMemorySize,FreePhysicalMemory
$TotalVisibleMemorySize = [math]::Round((($memory.TotalVisibleMemorySize) / 1024)/ 1024)
$PercentUsedMemory = [math]::Round((($memory.TotalVisibleMemorySize – $memory.FreePhysicalMemory) / ($memory.TotalVisibleMemorySize)) * 100)
#Adicionando uma nova linha
$KeyData = $null
$KeyData = New-Object PSObject
$KeyData | Add-Member -MemberType NoteProperty -Name “Name” -Value “$Name”
$KeyData | Add-Member -MemberType NoteProperty -Name “Manufacturer” -Value “$Manufacturer“
$KeyData | Add-Member -MemberType NoteProperty -Name “Serialnumber” -Value “$Serialnumber“
$KeyData | Add-Member -MemberType NoteProperty -Name “ProcessorName” -Value “$ProcessorName”
$KeyData | Add-Member -MemberType NoteProperty -Name “ProcessorLoadPercentage” -Value “$ProcessorLoadPercentage”
$KeyData | Add-Member -MemberType NoteProperty -Name “DiskModels” -Value “$DiskModels”
$KeyData | Add-Member -MemberType NoteProperty -Name “PercentIdleTime” -Value “$PercentIdleTime”
$KeyData | Add-Member -MemberType NoteProperty -Name “PercentDiskTime” -Value “$PercentDiskTime”
$KeyData | Add-Member -MemberType NoteProperty -Name “TotalVisibleMemorySize” -Value “$TotalVisibleMemorySize”
$KeyData | Add-Member -MemberType NoteProperty -Name “PercentUsedMemory” -Value “$PercentUsedMemory”
$KeysArray += $KeyData
write-host ” – OK” -ForegroundColor Green
write-host “————————————————————————“
}
Else
{
write-host ” – Sem acesso” -ForegroundColor Red
write-host “————————————————————————“
}
}
$KeysArray | ft
Execute o código e obtenha a lista.
Fontes/Referências
NVLAN – Como obter o Distinguished Name (DN) no Active Directory
NVLAN – Criar uma variável com colunas no PowerShell
https://community.spiceworks.com/t/powershell-script-to-get-machines-serial-number-with-computer-name/835442
https://learn.microsoft.com/en-us/archive/technet-wiki/52273.active-directory-how-to-find-inactive-computers-in
Mais Informações
Esperamos ter te ajudado e estaremos sempre a disposição para mais informações.
Se você tem interesse em algum assunto específico, tem alguma dúvida, precisa de ajuda, ou quer sugerir um post, entre em contato conosco pelo e-mail equipe@nvlan.com.br.