# Invoke-Command adding data to my csv export

**URL:** <https://forums.powershell.org/t/invoke-command-adding-data-to-my-csv-export/20725>\
**Category:** PowerShell Help\
**Created:** [October 24, 2022, 8:22pm UTC](https://forums.powershell.org/t/invoke-command-adding-data-to-my-csv-export/20725 "2022-10-24T20:22:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![landonveitch](https://avatars.discourse-cdn.com/v4/letter/l/96bed5/32.png) [@landonveitch](https://forums.powershell.org/u/landonveitch)\
**Post date:** [October 24, 2022, 8:22pm UTC](https://forums.powershell.org/t/invoke-command-adding-data-to-my-csv-export/20725/1 "2022-10-24T20:22:55Z")

</div>

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:

```auto
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.

```auto
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?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [October 24, 2022, 9:17pm UTC](https://forums.powershell.org/t/invoke-command-adding-data-to-my-csv-export/20725/2 "2022-10-24T21:17:58Z")

</div>

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. 😉

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:

```auto
$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

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/invoke-command-adding-data-to-my-csv-export/20725/3 "2024-05-16T20:16:31Z")

</div>


