Hi All,
I made this function (see very bottom) to use in a script to get some info about disks. However some properties appear as a key/value pair instead of just the value, the problem is only for the bitlocker information. Some properties are ok and I can’t figure out why
When I use [string]($blv | Select-Object -ExpandProperty volumestatus) this works as intended ie.
I get just the text I need when using for example $data.Volumestatus. Other properties from other sources, for example Get-CimInstance work fine.
\> $data = Get-DiskInfo -ComputerName TESTPC
\> $data.VolumeStatus
FullyEncrypted
\> $data.volumetype
Value
-----
OperatingSystem
\> $data.MountPoint
C:
function Get-DiskInfo {
[CmdletBinding()]
param (
# Parameter help description
[Parameter(Mandatory)]
[string[]]
$ComputerName,
# Parameter help description
[Parameter()]
[pscredential]
$Credential,
[string]$ErrorLogFilePath = "c:\temp\EncryptDrives.log"
)
begin {}
process {
foreach ($item in $computername) {
try {
$Params = @{}
if ($Credential) {
$Params['Credential'] = $Credential
}
invoke-command @params -ComputerName $item -ScriptBlock {
$tpm = get-tpm
# Just gets Local fixed disks
$Params = @{
ClassName = "win32_logicaldisk"
Filter = "drivetype=3"
ErrorAction = "Stop"
}
$disks = Get-CimInstance @Params
foreach ($disk in $disks) {
$blv = Get-BitLockerVolume -MountPoint $($disk.DeviceID)
$obj = [PSCustomObject]@{
MountPoint = $disk.DeviceID
DriveType = $disk.DriveType
VolumeName = $disk.VolumeName
VolumeStatus = [string]($blv | Select-Object -ExpandProperty volumestatus)
ProtectionStatus = ($blv | Select-Object -ExpandProperty ProtectionStatus)
VolumeType = $blv.VolumeType
computername = $env:computername
tpmEnabled = $tpm.tpmEnabled
} #PSCustomObject
Write-Output $obj
} #foreach
} #Invoke-command
}
catch {
$item | Out-File $ErrorLogFilePath -Append
Write-Error "Error:$_"
} # try/catch
} #foreach
} #PROCESS
end {}
} #function Get-DiskInfo
$data = Get-DiskInfo -ComputerName TESTPC
In the custom object I have tried different ways of assigning the property with the $blv variable.
Thanks in advance