You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SCCM服务器构建任务序列中Set-CimInstance执行失败求助

SCCM任务序列中修改驱动器盘符失败问题

问题概述

在SCCM服务器构建任务序列中执行PowerShell脚本修改指定驱动器盘符时遭遇错误,但手动在服务器上运行该脚本可正常完成盘符分配。该任务此前在RAID配置的HPE ML110服务器上可正常运行,目前老款Lenovo服务器仍能正常执行。

执行的脚本代码

$LocalDataDrive = "E"
$dataDrive = Get-Volume | Where-Object {$_.FileSystemLabel -eq "Data"}
if($dataDrive){
    Write-Output "    DEBUG: Change Data drive letter to: $LocalDataDrive"
    $dataDriveLetter = $dataDrive.DriveLetter
    Get-CimInstance -Class Win32_Volume -Filter "DriveLetter = '${dataDriveLetter}:'" | Set-CimInstance -Arguments @{DriveLetter="${LocalDataDrive}:"
}

任务序列执行报错日志

PS>TerminatingError(Set-CimInstance): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Not supported "
>> TerminatingError(Set-CimInstance): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Not supported "
>> TerminatingError(Set-CimInstance): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Not supported "
The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Not supported
Set-CimInstance : Not supported
At D:\_SMSTaskSequence\Packages\A01002CB\HPE-New-StoreHost.ps1:111 char:89
+ ... etter}:'" | Set-CimInstance -Arguments @{DriveLetter="${LocalDataDriv ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotImplemented: (Win32_Volume: D...4-adba-0529...):CimInstance) [Set-CimInstance], CimEx
   ception
    + FullyQualifiedErrorId : HRESULT 0x8004100c,Microsoft.Management.Infrastructure.CimCmdlets.SetCimInstanceCommand
PS>$global:?
False

实用解决方向

  • 切换执行工具:改用diskpart替代CIM操作,在任务序列环境中兼容性更强。创建diskpart脚本文件(如change_drive_letter.txt):
    select volume <原盘符对应的卷编号>
    assign letter=E
    
    再通过PowerShell调用:diskpart /s "脚本文件路径"
  • 检查执行上下文差异:SCCM任务序列以本地系统账户运行,手动执行用管理员账户,可在脚本中添加错误捕获逻辑,或临时调整ErrorActionPreference为Continue排查具体问题。
  • 等待卷初始化完成:任务序列执行时目标卷可能未完全就绪,添加循环检查逻辑,确认卷状态正常后再执行盘符修改操作。
  • 修复WMI组件:针对报错的HRESULT 0x8004100c(WMI不支持操作),重启Winmgmt服务,或运行winmgmt /resetrepository重置WMI存储库。

内容的提问来源于stack exchange,提问作者sjmckeeman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 03:09:27