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

如何通过PowerShell获取Commvault中指定MediaAgent上的运行中任务

前置依赖
  • 运行环境需安装Commvault官方PowerShell模块(v11 SP20及以上版本),可执行Install-Module -Name Commvault -Scope AllUsers安装,需本地管理员权限
  • 执行账号需拥有CommCell环境的作业查看权限
  • 执行机器可正常访问CommServe服务器的Web服务端口(默认HTTP 81、HTTPS 443)
完整实现脚本

脚本支持传入-MediaAgentName参数直接查询对应MediaAgent上的所有运行中任务:

param(
    [Parameter(Mandatory=$true, HelpMessage="指定要查询的MediaAgent服务器名称")]
    [string]$MediaAgentName
)

# 导入Commvault模块
try {
    Import-Module Commvault -ErrorAction Stop
} catch {
    Write-Error "Commvault PowerShell模块未安装,请先安装后重试"
    exit 1
}

# 连接CommServe,替换为你实际的CommServe地址
$commServeAddr = "替换为你的CommServe服务器域名/IP"
$cred = Get-Credential -Message "输入CommCell登录凭据"
try {
    Connect-CVServer -Server $commServeAddr -Credential $cred -ErrorAction Stop
} catch {
    Write-Error "CommServe连接失败,请检查地址、凭据及网络连通性"
    exit 1
}

# 获取目标MediaAgent对象
try {
    $targetMA = Get-CVMediaAgent -Name $MediaAgentName -ErrorAction Stop
} catch {
    Write-Error "未找到名称为 $MediaAgentName 的MediaAgent,请检查名称拼写"
    Disconnect-CVServer
    exit 1
}

# 查询该MediaAgent上的所有运行中任务
$runningJobs = Get-CVJob -MediaAgentId $targetMA.Id -JobStatus Running

# 输出结果
if ($runningJobs.Count -eq 0) {
    Write-Host "当前MediaAgent $MediaAgentName 上无运行中任务"
} else {
    Write-Host "查询到 $($runningJobs.Count) 个运行中任务,信息如下:"
    $runningJobs | Select-Object JobId, JobType, ClientName, SubclientName, StartTime, ProgressPercent | Format-Table -AutoSize
}

# 断开CommServe连接
Disconnect-CVServer
使用说明
  • 执行脚本时传入MediaAgent名称即可,示例:.\Get-MARunningJobs.ps1 -MediaAgentName "MA01.contoso.com"
  • 返回结果默认展示作业ID、作业类型、所属客户端、子客户端、启动时间、进度百分比,可根据需求自行调整返回字段
注意事项
  • 若使用的Commvault版本低于v11 SP20,无官方PowerShell模块的情况下,可封装调用Commvault REST API的GET /JobManager/Jobs接口,请求参数指定mediaAgentId和jobStatus=Running即可实现相同效果
  • 请勿在生产环境未授权的情况下执行查询脚本,避免对CommServe性能造成不必要影响

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 19:45:02