在powershell中减去2字节值

q1qsirdb  于 4个月前  发布在  Shell
关注(0)|答案(1)|浏览(84)

我试图在下面的代码中获得总磁盘值的85%,然后减去它的自由值。需要创建一个文本文件,结果值测试在雪警报。

$GetFreeSpace = Get-PSDrive C | Select-Object Used,Free
[int64]$Freespace = $GetFreeSpace.Free

# Get disk size 85%
$disk = Get-Volume -DriveLetter C 
$totalSize = $disk.Size
[int64]$eightyFivePercent = $totalSize * 0.85

# File to be created for Warning Alert (85%)
[int64]$File_size_for_warning = $eightyFivePercent - $GetFreeSpace

$file_size = $File_size_for_warning 
$file_Path "C:\Script\test_file_warning_alert.txt"
$stream = [System.IO.File]::CreateText($filePath)
$stream.BaseStream.SetLength($fileSize)
$stream.Close()

字符串
但是在做减法的时候,我得到了下面的错误,

Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Subtraction'.
At line:11 char:1


请让我知道我在这里做错了什么

bvjveswy

bvjveswy1#

如果你看一下$GetFreeSpace的输出,你会注意到它是一个对象而不是一个值。

[int64]$Freespace = $GetFreeSpace.Free

字符串
但这里你使用的是对象而不是你创造的值。

[int64]$File_size_for_warning = $eightyFivePercent - $GetFreeSpace


把台词改成

[int64]$File_size_for_warning = $eightyFivePercent - $FreeSpace

相关问题