CuriousMAUser
asked on
What do I modify in this PowerShell script to query only the servers for OS Information & Architecture details?
Get-OsInfoFromAdComputers. ps1
Function Get-ADComputersTestConnect ion
{
Param([switch]$showErrors)
([adsisearcher]"objectcate gory=compu ter").find all() |
ForEach-Object {
try
{
Test-Connection -ComputerName ([adsi]$_.path).cn -BufferSize 16 `
-Count 1 -TimeToLive 1 -EA stop }
Catch [system.exception]
{
if($showErrors)
{ $error[0].tostring() }
}
} #end foreach-object
} #End function Get-ADComputersTestConnect ion
Function Get-OsInfo
{
Param(
[string]$computer
)
Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer
} #end function Get-OsInfo
# *** EntryPoint to Script ***
Get-ADComputersTestConnect ion |
ForEach-Object {
Get-OsInfo -computer $_.address } |
Sort-Object -Property osarchitecture |
Format-Table -Property @{ Label="name"; Expression={$_.csname} },
@{ Label = "os-bits"; Expression = {$_.osArchitecture} },
@{ Label = "OsEdition" ; Expression = {$_.caption} } -AutoSize |
Tee-Object -FilePath c:\Scripts\OSReport.txt
Function Get-ADComputersTestConnect
{
Param([switch]$showErrors)
([adsisearcher]"objectcate
ForEach-Object {
try
{
Test-Connection -ComputerName ([adsi]$_.path).cn -BufferSize 16 `
-Count 1 -TimeToLive 1 -EA stop }
Catch [system.exception]
{
if($showErrors)
{ $error[0].tostring() }
}
} #end foreach-object
} #End function Get-ADComputersTestConnect
Function Get-OsInfo
{
Param(
[string]$computer
)
Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer
} #end function Get-OsInfo
# *** EntryPoint to Script ***
Get-ADComputersTestConnect
ForEach-Object {
Get-OsInfo -computer $_.address } |
Sort-Object -Property osarchitecture |
Format-Table -Property @{ Label="name"; Expression={$_.csname} },
@{ Label = "os-bits"; Expression = {$_.osArchitecture} },
@{ Label = "OsEdition" ; Expression = {$_.caption} } -AutoSize |
Tee-Object -FilePath c:\Scripts\OSReport.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.