0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Servicenowにアクセス

Posted at

エラーの原因は以下の2点です:


❌ 原因①:Write-Host の文字列中に 全角の記号や特殊文字 が混ざっており、クォーテーションが正しく閉じられていない

この部分:

Write-Host "笶・繧ィ繝ゥ繝シ縺檎匱逕溘@縺セ縺励◆・・ $_.Exception.Message

"(ダブルクォーテーション) で始まっているのに、閉じる " がないため、構文エラーが出ています。


✅ 修正済みバージョンのスクリプト(日本語対応済み)

# ServiceNow接続情報
$instance = "dev285867"
$username = "admin"
$password = "ZE3g^TzwfE0^"

# 検索条件なしで1件取得
$url = "https://$instance.service-now.com/api/now/table/problem?sysparm_limit=1"

# 認証情報
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($username, $securePassword)

# REST API 呼び出し
try {
    $response = Invoke-RestMethod -Uri $url -Method Get -Credential $credential -Headers @{
        "Accept" = "application/json"
    }

    if ($response.result -and $response.result.Count -gt 0) {
        Write-Host "✅ レコード取得成功!"
        $response.result | Format-List
    } else {
        Write-Host "⚠️ レコードが見つかりませんでした。"
    }

} catch {
    Write-Host "❌ エラーが発生しました:" + $_.Exception.Message
}

🔍 修正ポイントまとめ

修正前 修正後
Write-Host "xxx $_.Exception.Message Write-Host "xxx" + $_.Exception.Message
" で始めたら必ず " で閉じる必要があります OK
エラー表示を "文字列" + エラー内容 形式に変更 OK

これで構文エラーは解消されるはずです。再度実行してみてください。
もし次に表示されるエラーメッセージやレスポンスがあれば、それを教えてもらえればさらにサポートできます!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?