Need Powershell Help

I need help performing the WMI Query on all computers in the OU as seen below,  All data returned, must be saved.   Thanks   I am not a  powershell guru so please take your time to help.
Import-Module -Name ActiveDirectory
Get-ADComputer -filter * -SearchBase "OU=Center Manager,OU=Clinical Desktops,OU=Computer Accounts,DC=ppct,DC=world"
$computer = $_

Foreach-Object {

 Get-WmiObject -ComputerName $computer -Namespace "root/CIMV2/Security/MicrosoftVolumeEncryption" -Query "SELECT * FROM Win32_EncryptableVolume" | Where-Object {$_.ProtectionStatus -eq '1'}

 Select-Object ProtectionStatus
 } | 

Format-Table -Property * -AutoSize

Open in new window

LVL 9
stressedout2004Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
This will write the results (including errors) to a csv file, and display the results.
Import-Module -Name ActiveDirectory
$resultFile = 'C:\Temp\ProtectionStatus.csv'
$computerList = Get-ADComputer -filter * -SearchBase "OU=Center Manager,OU=Clinical Desktops,OU=Computer Accounts,DC=ppct,DC=world"

$computerList | Foreach-Object {
	$computerName = $_
	"Processing $($computerName) ..." | Write-Host -ForegroundColor White -NoNewline
	Try {
		Get-WmiObject -ComputerName $computerName -Namespace "root\CIMV2\Security\MicrosoftVolumeEncryption" -Query "SELECT DriveLetter, ProtectionStatus FROM Win32_EncryptableVolume" -ErrorAction Stop |
			Select-Object -Property @{n='ComputerName'; e={$computerName}}, DriveLetter, ProtectionStatus, Error
		" OK" | Write-Host -ForegroundColor Green
	} Catch {
		$_ | Select-Object -Property @{n='ComputerName'; e={$computerName}}, DriveLetter, ProtectionStatus, @{n='Error'; e={$_.Exception.Message}}
		" ERROR" | Write-Host -ForegroundColor Red
	}
} | Export-Csv -NoTypeInformation -Path $resultFile
"Results written to '$($resultFile)'" | Write-Host -ForegroundColor White
Import-Csv -Path $resultFile | Out-GridView

Open in new window

1
Senior IT System EngineerIT ProfessionalCommented:
The script looks good, however, when I execute it, I got these error:

RPC Error ?
note, all of the Laptops are online when I doublecheck on the list.
0
oBdACommented:
Well, the error message doesn't lie. Probably the firewall, or remote management is disabled.
You can replace/comment out line 3, and use $computerList = '.' to run it against the local computer.
1
Discover the Answer to Productive IT

Discover app within WatchGuard's Wi-Fi Cloud helps you optimize W-Fi user experience with the most complete set of visibility, troubleshooting, and network health features. Quickly pinpointing network problems will lead to more happy users and most importantly, productive IT.

FOXActive Directory/Exchange EngineerCommented:
Obda,
Try using the Invoke-Command in your script against the list of computers.  The remote management may be disabled like you said
1
Senior IT System EngineerIT ProfessionalCommented:
Fox,
so if the script is executed using Invoke-Command, it will work despite the remote management is disabled?

Obda, the result after changing:
$computerList = "localhost"
$computerList = "."


is
Localhost.JPG
is that expected ?
0
stressedout2004Author Commented:
The script is working, looking to test this now which is relative to the RPC error.
https://www.infrasightlabs.com/setting-wmi-access-ad-gpo
2
oBdACommented:
Senior IT System Engineer,
that would be expected if you have a single volume C: and it's not Bitlocker encrypted.
1
Senior IT System EngineerIT ProfessionalCommented:
Nice, so yes the code works when it is executed under Run As Administrator.
1
stressedout2004Author Commented:
I believe that I need the script to include a FQDN for each computer name .   My server is in another site and its using the NetBIOS name which could be why the RPC error is occurring.  Any way to have it include FQDN foo.local
0
stressedout2004Author Commented:
I can also execute this command from the space server where I'm executing the above script from without any problems.

Get-WmiObject win32_SystemEnclosure -Computer d3570-3049.ppct.world
0
oBdACommented:
Sorry, my bad after all; a Select-Object went AWOL when posting ...
Import-Module -Name ActiveDirectory
$resultFile = 'C:\Temp\ProtectionStatus.csv'
$computerList = Get-ADComputer -filter * -SearchBase "OU=Center Manager,OU=Clinical Desktops,OU=Computer Accounts,DC=ppct,DC=world" |
	Select-Object -ExpandProperty DNSHostName

$computerList | Foreach-Object {
	$computerName = $_
	"Processing $($computerName) ..." | Write-Host -ForegroundColor White -NoNewline
	Try {
		Get-WmiObject -ComputerName $computerName -Namespace "root\CIMV2\Security\MicrosoftVolumeEncryption" -Query "SELECT DriveLetter, ProtectionStatus FROM Win32_EncryptableVolume" -ErrorAction Stop |
			Select-Object -Property @{n='ComputerName'; e={$computerName}}, DriveLetter, ProtectionStatus, Error
		" OK" | Write-Host -ForegroundColor Green
	} Catch {
		$_ | Select-Object -Property @{n='ComputerName'; e={$computerName}}, DriveLetter, ProtectionStatus, @{n='Error'; e={$_.Exception.Message}}
		" ERROR" | Write-Host -ForegroundColor Red
	}
} | Export-Csv -NoTypeInformation -Path $resultFile
"Results written to '$($resultFile)'" | Write-Host -ForegroundColor White
Import-Csv -Path $resultFile | Out-GridView

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stressedout2004Author Commented:
Can the script be modified to allow the domain ppct.world when it loops through the computer names?
1
stressedout2004Author Commented:
I need some modifications please .

I need to append the domain ppct.world to $computerName

The WMI query must be this query
Get-WmiObject -ComputerName $computerName Namespace "root/CIMV2/Security/MicrosoftVolumeEncryption" -Query "SELECT * FROM Win32_EncryptableVolume" | Where-Object {$_.ProtectionStatus -eq '1'}

vs this query.

Get-WmiObject -ComputerName $computerName -Namespace "root\CIMV2\Security\MicrosoftVolumeEncryption" -Query "SELECT DriveLetter, ProtectionStatus FROM Win32_EncryptableVolume"

I need all of these fields populated

__GENUS                          : 2
__CLASS                          : Win32_EncryptableVolume
__SUPERCLASS                     :
__DYNASTY                        : Win32_EncryptableVolume
__RELPATH                        : Win32_EncryptableVolume.DeviceID="\\\\?\\Volume{Commented OUT}\\"
__PROPERTY_COUNT                 : 8
__DERIVATION                     : {}
__SERVER                         : TestSystem
__NAMESPACE                      : root\CIMV2\Security\MicrosoftVolumeEncryption
__PATH                           : \\TestSystem\root\CIMV2\Security\MicrosoftVolumeEncryption:Win32_EncryptableVolume.DeviceID=
                                   "\\\\?\\Volume{Commented OUT}\\"
ConversionStatus                 : 1
DeviceID                         : \\?\Volume{Commented OUT}\
DriveLetter                      : C:
EncryptionMethod                 : 6
IsVolumeInitializedForProtection : True
PersistentVolumeID               : {Commented OUT}
ProtectionStatus                 : 1
VolumeType                       : 0
PSComputerName                   : TestSystem
0
oBdACommented:
The latest version is already using the FQDN as retrieved from AD, so there's no need to add it explicitly.
The properties starting with "__" are specific to WMI; you could collect them, but I don't really see the point.
Import-Module -Name ActiveDirectory
$resultFile = 'C:\Temp\ProtectionStatus.csv'
$computerList = Get-ADComputer -filter * -SearchBase "OU=Center Manager,OU=Clinical Desktops,OU=Computer Accounts,DC=ppct,DC=world" |
	Select-Object -ExpandProperty DNSHostName

$properties = 'ConversionStatus', 'DeviceID', 'DriveLetter', 'EncryptionMethod', 'IsVolumeInitializedForProtection', 'PersistentVolumeID', 'ProtectionStatus', 'VolumeType'
$computerList | Foreach-Object {
	$computerName = $_
	"Processing $($computerName) ..." | Write-Host -ForegroundColor White -NoNewline
	$(Try {
		Get-WmiObject -ComputerName $computerName -Namespace "root\CIMV2\Security\MicrosoftVolumeEncryption" -Query "SELECT * FROM Win32_EncryptableVolume" -ErrorAction Stop
		" OK" | Write-Host -ForegroundColor Green
	} Catch {
		$_ | Select-Object -Property @{n='Error'; e={$_.Exception.Message}}
		" ERROR" | Write-Host -ForegroundColor Red
	}) | Select-Object -Property (@(@{n='ComputerName'; e={$computerName}}) + $properties + 'Error')
} | Sort-Object -Property ComputerName, DriveLetter | Export-Csv -NoTypeInformation -Path $resultFile
"Results written to '$($resultFile)'" | Write-Host -ForegroundColor White
Import-Csv -Path $resultFile | Out-GridView

Open in new window

1
stressedout2004Author Commented:
0
Senior IT System EngineerIT ProfessionalCommented:
OBDA code works perfectly fine, thanks for sharing it here man:

Import-Module -Name ActiveDirectory
$resultFile = 'C:\Temp\ProtectionStatus.csv'
$computerList = Get-ADComputer -filter * -SearchBase "OU=Center Manager,OU=Clinical Desktops,OU=Computer Accounts,DC=ppct,DC=world" |
	Select-Object -ExpandProperty DNSHostName

$properties = 'ConversionStatus', 'DeviceID', 'DriveLetter', 'EncryptionMethod', 'IsVolumeInitializedForProtection', 'PersistentVolumeID', 'ProtectionStatus', 'VolumeType'
$computerList | Foreach-Object {
	$computerName = $_
	"Processing $($computerName) ..." | Write-Host -ForegroundColor White -NoNewline
	$(Try {
		Get-WmiObject -ComputerName $computerName -Namespace "root\CIMV2\Security\MicrosoftVolumeEncryption" -Query "SELECT * FROM Win32_EncryptableVolume" -ErrorAction Stop
		" OK" | Write-Host -ForegroundColor Green
	} Catch {
		$_ | Select-Object -Property @{n='Error'; e={$_.Exception.Message}}
		" ERROR" | Write-Host -ForegroundColor Red
	}) | Select-Object -Property (@(@{n='ComputerName'; e={$computerName}}) + $properties + 'Error')
} | Sort-Object -Property ComputerName, DriveLetter | Export-Csv -NoTypeInformation -Path $resultFile
"Results written to '$($resultFile)'" | Write-Host -ForegroundColor White
Import-Csv -Path $resultFile | Out-GridView

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.