import-module activedirectory
get-ADcomputer -Filter * |
Where-Object {$a=$_.name; $_.DistinguishedName -ne "CN=$a,OU=Disable,DC=Test,DC=lan"} |
Sort-Object name | Select-Object name | Export-csv C:\Invent\AllComputers.csv -NoTypeInformation
import-csv c:\Invent\AllComputers.csv | foreach {
$a=$_.name
if ((Test-connection $a -count 2 -quiet) -eq "True")
{
if ((Get-WmiObject -computername $a Win32_OperatingSystem) -eq $null)
{
Write-Host " " -ForeGroundColor Green $a
"" | out-file c:\Invent\Comp\$a.txt
Get-WmiObject -computername $a Win32_OperatingSystem |
select-object csname, caption, Serialnumber, csdVersion |
ft @{Label=" "; Expression={$_.CSname}},
@{label=""; Expression={$_.caption}},
@{label=""; Expression={$_.csdVersion}},
@{label=" "; Expression={$_.SerialNumber}} -auto -wrap |
out-file c:\Invent\Comp\$a.txt -append
Get-WmiObject -computername $a Win32_ComputerSystemProduct | select-object UUID |
ft UUID -autosize | out-file c:\Invent\Comp\$a.txt -append
"" | out-file c:\Invent\Comp\$a.txt -append
Get-WmiObject -computername $a Win32_Processor | select-object name, SocketDesignation, Description |
ft @{label=""; Expression={$_.name}},
@{label=""; Expression={$_.SocketDesignation}},
@{label=""; Expression={$_.Description}} -auto -wrap | out-file c:\Invent\Comp\$a.txt -append
" " | out-file c:\Invent\Comp\$a.txt -append
Get-WmiObject -computername $a Win32_BaseBoard | select-object Manufacturer, Product, SerialNumber |
ft @{label=""; Expression={$_.manufacturer}},
@{label=""; Expression={$_.Product}},
@{label=" "; Expression={$_.SerialNumber}} -auto -wrap |
out-file c:\Invent\Comp\$a.txt -append
" " | out-file c:\Invent\Comp\$a.txt -append
Get-WmiObject -computername $a Win32_DiskDrive | select-object Model, Partitions, Size, interfacetype |
ft @{Label=""; Expression={$_.Model}},
@{Label=" "; Expression={$_.Partitions}},
@{Label=" ()"; Expression={($_.Size/1GB).tostring("F00")}},
@{Label=""; Expression={$_.interfaceType}} -auto -wrap |
out-file c:\Invent\Comp\$a.txt -append
" " | out-file c:\Invent\Comp\$a.txt -append
Get-WmiObject -computername $a Win32_LogicalDisk -Filter "DriveType=3" | select-object DeviceID, FileSystem, Size, FreeSpace |
ft @{Label=""; Expression={$_.DeviceID}},
@{Label=" "; Expression={$_.FileSystem}},
@{Label=" ()"; Expression={($_.Size/1GB).tostring("F00")}},
@{Label=" ()"; Expression={($_.FreeSpace/1GB).tostring("F00")}} -auto -wrap |
out-file c:\Invent\Comp\$a.txt -append
" " | out-file c:\Invent\Comp\$a.txt -append
Get-WmiObject -computername $a Win32_Physicalmemory | Select-Object capacity, DeviceLocator |
ft @{Label=" ()"; Expression={($_.capacity/1MB).tostring("F00")}},
@{Label=""; Expression={$_.DeviceLocator}} -auto -wrap |
out-file c:\Invent\Comp\$a.txt -append
"" | out-file c:\Invent\Comp\$a.txt -append
Get-WmiObject -computername $a Win32_videoController |
Select-Object name, AdapterRAM, VideoProcessor |
ft @{Label=""; Expression={$_.name}},
@{Label=" ()"; Expression={($_.AdapterRAM/1MB).tostring("F00")}},
@{Label=""; Expression={$_.VideoProcessor}} -auto -wrap |
out-file c:\Invent\Comp\$a.txt -append
" " | out-file c:\Invent\Comp\$a.txt -append
$OS=Get-WmiObject -computername $a Win32_OperatingSystem | foreach {$_.caption}
if ($OS -eq "Microsoft Windows 2000 Professional")
{
Get-WmiObject -computername $a Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled=True" |
Select-Object caption,MACaddress |
ft @{Label=""; Expression={$_.caption}},
@{Label="MAC "; Expression={$_.MACAddress}} -auto -wrap |
out-file c:\Invent\Comp\$a.txt -append
}
else
{
Get-WmiObject -computername $a Win32_NetworkAdapter -Filter "NetConnectionStatus>0" |
Select-Object name, AdapterType, MACAddress |
ft @{Label=""; Expression={$_.name}},
@{Label="MAC "; Expression={$_.MACAddress}},
@{Label=""; Expression={$_.AdapterType}} -auto -wrap |
out-file c:\Invent\Comp\$a.txt -append
}
}
Write-Host " " -ForeGroundColor Green $a
I did exclusively for myself, for it is nice to know what PowerShell is doing at the moment.Source: https://habr.com/ru/post/124386/
All Articles