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

在VS Code中运行Hadoop词频统计PowerShell脚本遇权限及空值错误

Azure HDInsight MapReduce任务执行报错:Forbidden及JobId为空问题

我在Visual Studio Code中编写了用于运行Hadoop词频统计的PowerShell脚本(保存为.ps1文件),执行时出现连锁错误:调用Start-AzHDInsightJob返回**Forbidden(禁止访问)**状态码,导致变量$wordCountJob为空;后续执行Wait-AzHDInsightJob时,因JobId参数为空触发报错。

脚本内容

Write-Host "Getting the context of your profile on Microsoft Azure..." -ForegroundColor Green 
$context = Get-AzContext

if ($null -eq $context) { Connect-AzAccount }

$context

$subscription = "5054f72b-16ed-4894-8bf5-fe7ad8fa20e3" 
$resourceGroupName = "BUS5WB" 
$clusterName = "bus5wb-hydra-s1-2022"

Write-Host "Selecting the subscription the HDInsight cluster is on..." -ForegroundColor Green 
Select-AzSubscription $subscription

Write-Host "Logging into the HDInsight cluster..." -ForegroundColor Green 
$cred = Get-Credential -Message "Enter the HDInsight cluster HTTP user credential:" 

$wordCountJobDefinition = New-AzHDInsightMapReduceJobDefinition     -JarFile "/example/jars/hadoop-mapreduce-examples.jar" -ClassName "wordcount"     -Arguments "/example/data/20450461/2Star.txt", ` "/example/data/20450461/2Star"

#Submit the job to the cluster 
Write-Host "Start the MapReduce job..." -ForegroundColor Green 
$wordCountJob = Start-AzHDInsightJob     -ClusterName $clusterName -JobDefinition $wordCountJobDefinition     -HttpCredential $cred -ResourceGroupName $resourceGroupName

#Wait for the job to complete 
Write-Host "Wait for the job to complete..." -ForegroundColor Green 
Wait-AzHDInsightJob     -ClusterName $clusterName -JobId $wordCountJob.JobId ` -HttpCredential $cred

错误输出内容

Start the MapReduce job...
Start-AzHDInsightJob: C:\Users\20450461\Documents\2Star.ps1:48:17
Line |
  48 |  $wordCountJob = Start-AzHDInsightJob `
     |                  ~~~~~~~~~~~~~~~~~~~~~~
     | Operation returned an invalid status code 'Forbidden'

Wait for the job to complete...
Wait-AzHDInsightJob: C:\Users\20450461\Documents\2Star.ps1:58:12
Line |
  58 |      -JobId $wordCountJob.JobId `
     |             ~~~~~~~~~~~~~~~~~~~
     | Cannot bind argument to parameter 'JobId' because it is null.

内容的提问来源于stack exchange,提问作者Amanh Jonathan Bedi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 06:36:32