Invoke-Command adding data to my csv export

All,

This is a dumb question I know but its bugging me that I cant figure out why this is happening. So I have the below line that returns the 3 columns I have selected and works as I want it to…for a local machine:

Get-BitLockerVolume | Select -Property ComputerName, VolumeStatus, ProtectionStatus | Export-Csv -Path "$env:USERPROFILE\Desktop\VolumeStatus.csv" -NoTypeInformation -Append -Force

However…when I try to run this against a list of servers in a script block, it returns my 3 fields but also adds a PSShowComputerName, RunspaceId, and PSComputerName.

Foreach ($Server in $Servers) {
    $VolumeStatus = Invoke-Command -computername $Server -scriptblock { Get-BitLockerVolume | Select -Property ComputerName, VolumeStatus, ProtectionStatus | Export-Csv -Path "$env:USERPROFILE\Desktop\VolumeStatus.csv" -NoTypeInformation -Append -Force }
    }

Can someone tell me what I am missing to stop it from adding those unnecessary fields?

These properties are added to your convinience since not all commands return a property ComputerName. If you don’t want them you can use Select-Object -ExcludeProperty to remove them. :wink:

But there are actually other issues with your code.
When you use $env:USERPROFILE inside a remote command you target the remote computer. So you should not get output on your local computer at all.
You have a variable assignment inside your script block but you never use this variable.
And since Invoke-Command is able to take an array of computernames you don’t need a loop at all.

Try this:

$ComputerNameList = 
'Server01',
'Server02'

Invoke-Command -ComputerName $ComputerNameList -ScriptBlock {
    Get-BitLockerVolume
} |
Select-Object -Property ComputerName, VolumeStatus, ProtectionStatus -ExcludeProperty RunspaceId |
    Export-Csv -Path "$env:USERPROFILE\Desktop\VolumeStatus.csv" -NoTypeInformation