I am using Powershell and I am trying to compare the free space of a drive to the size of files I want to put onto the drive, but it doesn't seem to like the comparison and I get the error below. I'm wondering if the name preceding each value is causing the issue. If this is the case, is there a way to properly compare these values while retaining the name, or would I have to store the named values as a separate variable?
Cannot compare "@{Zipped Space (GB)=65.6897087870166}" to "@{Free Space (GB)=-19.7659684484825}" because the objects are not the
same type or the object "@{Zipped Space (GB)=65.6897087870166}" does not implement "IComparable".
At G:\ManuallyCopyFiles.ps1:31 char:8
+ while ($zippedSize -gt $freeSpace)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException
+ FullyQualifiedErrorId : PSObjectCompareTo
$freeSpace = (Get-ChildItem -Path "\\filler\C$\Users\filler\blah\" -Recurse -Force -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum |
Select-Object @{Name="Free Space (GB)";Expression={465-$_.Sum/1gb}})
$zippedSize = (Get-ChildItem -Path $dest -Recurse -Force -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum |
Select-Object @{Name="Zipped Space (GB)";Expression={0+$_.Sum/1gb}})
#Checks to see if there is enough space for the zipped files; if not, it deletes the oldest folder until there is enough space.
while ($zippedSize -gt $freeSpace)
{
Get-ChildItem $remotePath | Sort CreationTime | Select -First 1 | Remove-Item
$freeSpace = (Get-ChildItem -Path "\\filler\C$\Users\filler\blah\" -Recurse -Force -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum |
Select-Object @{Name="Free Space (GB)";Expression={465-$_.Sum/1gb}})
}