Exporting non VMware computer from AD Online computer list as .CSV?
Posted: Sun Feb 02, 2020 9:47 pm
Hello All,
I'm trying to get all Physical server using Powershell but somehow it is not returning any result as .CSV using my script below:
The error is shown on my screen:
Thanks in advance.
I'm trying to get all Physical server using Powershell but somehow it is not returning any result as .CSV using my script below:
Code: Select all
Get-ADComputer -Properties OperatingSystem, OperatingSystemVersion, lastLogonTimestamp, lastLogon -Filter {Enabled -eq $True -and OperatingSystem -like "*Server*" } -SearchBase "DC=Domain,DC=com" |
Where-Object {(Test-Connection $_.Name -Count 1 -Quiet) -and ((Get-WmiObject -ComputerName $_.Name -Class Win32_BIOS).SerialNumber -notlike "*VMware*") } |
Select-Object -Property Name,
OperatingSystem,
OperatingSystemVersion,
@{N="LastLogonTimeStamp";E={[datetime]::FromFileTime($_.LastLogonTimeStamp)}},
@{N="LastLogon";E={[datetime]::FromFileTime($_.lastLogon)}} |
ForEach-Object {
Write-Host "Processing $($_.Name) ..." -ForegroundColor Green -BackgroundColor Black
$cs = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $_.Name
Select-Object -InputObject $_ -Property *,
@{Name="Model"; Expression={$cs.Model}},
@{Name="UserName"; Expression={$cs.UserName}},
@{Name="IPAddress"; Expression={(Resolve-DnsName -Name $cs.Name).IPAddress}}
} | Export-Csv -Path 'C:\Result\OnlinePhysicalServers.csv' -NoTypeInformation -UseCulture
I am executing this script under my DOMAIN\Administrator account in my DC, so not sure why it does not work with the above error and no .CSV file at all?Processing DCSVR-EX01 ... Get-WmiObject : The RPC server is unavailable.
At line:10 char:19
+ ... $cs = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Get-ADComputer : The server has returned the following error: invalid enumeration context.
At line:1 char:1
+ Get-ADComputer -Properties OperatingSystem, OperatingSystemVersion, l ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ADComputer], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
Thanks in advance.