# outputs not working as expected

**URL:** <https://forums.powershell.org/t/outputs-not-working-as-expected/13781>\
**Category:** PowerShell Help\
**Created:** [February 10, 2020, 6:13am UTC](https://forums.powershell.org/t/outputs-not-working-as-expected/13781 "2020-02-10T06:13:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ewanmalone](https://avatars.discourse-cdn.com/v4/letter/e/e8c25b/32.png) [@ewanmalone](https://forums.powershell.org/u/ewanmalone)\
**Post date:** [February 10, 2020, 6:13am UTC](https://forums.powershell.org/t/outputs-not-working-as-expected/13781/1 "2020-02-10T06:13:52Z")

</div>

Hi All

&nbsp;

definitely new to powershell and this is breaking me. i have a script that works fine until i run it through an invoke-command to do it remotely. ive pulled this out of a larger script but then this is in it messes up the output to csv and i end up with this

\<colgroup\>\<col style="width: 48pt;" width="64" /\> \</colgroup\>

| Length |
| 7 |
| 7 |
| |
| 7 |
| 6 |

Help me Powershell.org. You're my only hope
```
#this works until i put it through the invoke-command.

#some pointless notes on straight forward code 🙂

#create a file and put a couple of servers in it, change this to that file  
$complist = “C:\temp\ewan\computers.txt”

#change this where you want the output spitting out too  
$outreport = “C:\temp\ewan\superballs\_” + $((Get-Date).ToString(‘MM-dd-yyyy’)) + “.csv”

#Invoke command breaks this  
Invoke-Command -ComputerName (Get-Content $complist) -Credential $credentials -scriptblock {

#gets physical disks on device  
$colDisks = get-wmiobject Win32\_LogicalDisk -Filter “DriveType = 3”  
$Space = “No Space Issues”  
#works out %free on any disks  
foreach ($disk in $colDisks) {  
if ($disk.size -gt 0) {$PercentFree = [Math]::round((($disk.freespace/$disk.size) \* 100))}  
else {$PercentFree = 0}

$Drive = $disk.DeviceID  
“$Drive - $PercentFree”  
#if less that 10% free it should complain  
if ($PercentFree -le 10) {  
$Space = “Low on space”;  
}  
}

#writes some stuff that can by output to a csv  
$infoObject = New-Object PSObject

Add-Member -inputObject $infoObject -memberType NoteProperty -name “Disk Space” -value $Space -Force

$infoObject} | Select-Object \* -ExcludeProperty PSComputerName, RunspaceId, PSShowComputerName | Export-Csv -path $outreport -NoTypeInformation

#HALP
```
&nbsp;

---

<div class="post-metadata">

**Author:** ![shawnwat](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@shawnwat](https://forums.powershell.org/u/shawnwat)\
**Post date:** [February 14, 2020, 9:36am UTC](https://forums.powershell.org/t/outputs-not-working-as-expected/13781/2 "2020-02-14T09:36:16Z")

</div>

Line 36 “}” right after $infoObject. That should be at the end. I am not at a place to test to confirm.

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [February 14, 2020, 10:26am UTC](https://forums.powershell.org/t/outputs-not-working-as-expected/13781/3 "2020-02-14T10:26:50Z")

</div>

The script block code could be a bit more efficient, look at this:

```
Get-CimInstance -ClassName Win32_logicaldisk -Filter "DriveType = '3'" | 
Select-Object -Property DeviceID, 
                        DriveType, 
                        VolumeName, 
                        @{Name='FreeSpaceGB';Expression={"{0:N2}" -f ($_.FreeSpace /1GB)}},
                        @{Name="CapacityGB" ;Expression={"{0:N2}" -f ($_.Size /1GB)}},
                        @{Name="PctFree" ;Expression={([math]::Round(($_.FreeSpace /1GB) / ($_.Size /1GB) * 100))}}
```

Output:

```
DeviceID : C:
DriveType : 3
VolumeName : Windows-SSD
FreeSpaceGB : 277.10
CapacityGB : 475.69
PctFree : 58
```

Consider gathering information first and then do analysis. If you have results for computer, then just search for items that need action:

```
$result = @()
$result += [pscustomobject]@{ComputerName = 'Computer1';PctFree = 58}
$result += [pscustomobject]@{ComputerName = 'Computer2';PctFree = 9}
$result += [pscustomobject]@{ComputerName = 'Computer3';PctFree = 26}

$result | Where{$_.PctFree -le'10'}
```

---

<div class="post-metadata">

**Author:** ![p0wd3r](https://avatars.discourse-cdn.com/v4/letter/p/b5a626/32.png) [@p0wd3r](https://forums.powershell.org/u/p0wd3r)\
**Post date:** [February 18, 2020, 5:48pm UTC](https://forums.powershell.org/t/outputs-not-working-as-expected/13781/4 "2020-02-18T17:48:43Z")

</div>

Maybe PSDrive could work? You’ll have to do some translations for the CSV output though, I think…

```
$list = get-content C:\temp\ewan\computers.txt
$space = %{Invoke-Command -ComputerName $list {Get-PSDrive C}}
$space
```

&nbsp;

---

<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:30pm UTC](https://forums.powershell.org/t/outputs-not-working-as-expected/13781/5 "2024-05-16T20:30:26Z")

</div>

Closed on May 16, 2024, 8:30pm UTC


