Your manager wants to know informations about servers joined to the company's Active Directory and you want to retrieve informations with Powerhsell ?
Let's get started !
This script will retrieve servers informations in a CSV file like this :
"Computer
Name","Operating
System","Manufacturer","Model","RAM","CPU","IPV4","diskData"
"VirtualServer","Windows Server 2008 R2
Standard","VMware, Inc.","VMware Virtual
Platform","8 GB","2","10.193.17.42","C:
14.47 GB / 39.9 GB - D: 23.48 GB / 100 GB"
"PhysicalServer","Windows Server 2008 R2 Standard","IBM","IBM System x3550 M4 Server -[***43*G]-","32 GB","1","10.193.17.217","C: 33.36 GB / 100 GB - D: 373.54 GB / 456.61 GB"
"PhysicalServer","Windows Server 2008 R2 Standard","IBM","IBM System x3550 M4 Server -[***43*G]-","32 GB","1","10.193.17.217","C: 33.36 GB / 100 GB - D: 373.54 GB / 456.61 GB"
$ADComputerProperties = @(`
"Operatingsystem",
"OperatingSystemServicePack",
"Created",
"Enabled",
"LastLogonDate",
"IPv4Address",
"CanonicalName"
)
$SelectADComputerProperties = @(`
"Name",
"OperatingSystem",
"OperatingSystemServicePack",
"Created",
"Enabled",
"LastLogonDate",
"IPv4Address",
"CanonicalName"
)
$servers = Get-ADComputer -Filter
* -SearchBase
"ou=servers,ou=IT
resources,DC=ad,DC=dieteren,DC=be" -Properties
$ADComputerProperties | select $SelectADComputerProperties
Foreach ($server
in $servers)
{
$hostName = $server.Name
$operatingSystem = $server.OperatingSystem
$serverInfo =
(Get-WmiObject -Computername
$hostName Win32_ComputerSystem)
$manufacturer =
$serverInfo.Manufacturer
$model = $serverInfo.Model
$displayGB =
[math]::round($serverInfo.TotalPhysicalMemory/1024/1024/1024, 0)
$ipv4 =
$server.IPv4Address
$serverDiskInfo = (Get-WmiObject -Computername $server.Name win32_logicaldisk
-Filter "drivetype='3'")
$cpu =
@(Get-WmiObject -Class
Win32_processor -Computername
$hostName)
$c_socket =
$cpu.count
$c_core =
$cpu[0].NumberOfCores
* $c_socket
$c_logical =
$cpu[0].NumberOfLogicalProcessors
* $c_socket
$psobject =
New-Object -TypeName
psObject -Property
([ordered]@{
'Computer
Name' = $hostName
'Operating
System' = $operatingSystem
'Manufacturer'
= $manufacturer
'Model'
= $model
'RAM'
= "$displayGB GB"
'CPU'
= $c_socket
'IPV4'
= $ipv4
})
$psobject |
Add-Member -type
NoteProperty -name
diskData -Value
NotSet
$i=0
Foreach ($disk
in $serverDiskInfo)
{
$diskSize
= [math]::Round($disk.size / 1gb,2)
$diskFreeSpace
= [math]::Round($disk.freespace
/ gb,2)
Write-Host
"$($disk.deviceid) $diskFreeSpace GB / $diskSize GB"
if($i -eq 0) {
$psobject.diskData = "$($disk.deviceid) $diskFreeSpace GB / $diskSize GB"
}
else
{
$psobject.diskData
+= " - $($disk.deviceid) $diskFreeSpace GB / $diskSize GB"
}
$i++
}
$psobject |
Export-Csv C:\ComputerDetails.csv
-Append
}
Aucun commentaire:
Enregistrer un commentaire