powershell“;获取音量“;命令结束时出错

powershell“;获取音量“;命令结束时出错,powershell,Powershell,我尝试使用powershell创建磁盘监视器脚本。 在我的脚本中,我使用Get Volume命令检查卷的总大小。我在任务调度器中注册这个脚本,并在整个任务中运行它。然后我运行任务,我的脚本完成时出现以下错误 错误: TerminatingError(Get-Volume): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set

我尝试使用powershell创建磁盘监视器脚本。 在我的脚本中,我使用
Get Volume
命令检查卷的总大小。我在任务调度器中注册这个脚本,并在整个任务中运行它。然后我运行任务,我的脚本完成时出现以下错误

错误:

TerminatingError(Get-Volume): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: No MSFT_Volume objects found with property 'DriveLetter' equal to 'f'.  Verify the value of the property and retry."

C:\DIVA\Script\DataDiskUsedChecker\DiskUsed.ps1 : Microsoft.PowerShell.Cmdletization.Cim.CimJobException: No
MSFT_Volume objects found with property 'DriveLetter' equal to 'f'.  Verify the value of the property and retry.
At C:\DIVA\Script\DataDiskUsedChecker\DiskUsed.ps1:77 char:5
+     Write-Error $_.Exception
+     ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,DiskUsed.ps1
但一旦我使用powershell终端窗口运行
Get Volume
命令并再次运行任务,任务就会成功完成

如果有人能给我一些建议来解决这个问题,我们将不胜感激

代码:


谢谢你。对我有用

$diskD = Get-WmiObject Win32_LogicalDisk -ComputerName $env:computername -Filter "DeviceID='D:'" | Select-Object Size,FreeSpace

    $diskDSize = [math]::Round($diskD.Size/1GB, 2)
    $diskDFreeSpace = [math]::Round($diskD.FreeSpace/1GB, 2)

检查“Microsoft存储空间SMP”服务是否已禁用

应将其设置为手动


我打赌是某人的优化脚本/应用程序/实用程序将其设置为禁用。在我的例子中,这是由于VMware的操作系统优化工具。

您可以在脚本中发布代码行吗?在计划任务的帐户上下文下手动运行整个脚本时会发生什么情况?我添加了代码。行
$length=(Get Volume-DriveLetter f).Size
返回错误。当我使用计划任务的帐户手动运行此脚本时,它将成功完成。当我设置任务用户“Bultin\SYSTEM”时,这个错误永远不会发生。任务用户是非管理员帐户。但是,我认为我不需要向任务用户添加管理员权限。运行任务的用户显然没有驱动器
F
的映射,我不知道
get volume
命令有什么问题,WMI也为我工作。谢谢你的帮助!
$diskD = Get-WmiObject Win32_LogicalDisk -ComputerName $env:computername -Filter "DeviceID='D:'" | Select-Object Size,FreeSpace

    $diskDSize = [math]::Round($diskD.Size/1GB, 2)
    $diskDFreeSpace = [math]::Round($diskD.FreeSpace/1GB, 2)