Powershell script error


I’m running a powershell script to send notifications to slack from octopus. If I run the script manually (from octopus server) it works just fine but when it’s a process step is throwing an error.
This is the script:

$hook = “https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

$hook_config = @{
channel = “#octopus-deploy”;
username = “OctopusDeploy”;
icon_url = “http://octopusdeploy.com/content/resources/favicon.png”;

function Slack-Rich-Notification ($hook_config, $notification)
$payload = @{
channel = $hook_config[“channel”];
username = $hook_config[“username”];
icon_url = $hook_config[“icon_url”];
attachments = @(
fallback = $notification[“fallback”];
color = $notification[“color”];
fields = @(
title = $notification[“title”];
value = $notification[“value”];

Invoke-Restmethod -Method POST -ContentType application/json -Body ($payload | ConvertTo-Json -Depth 4) -Uri $hook


$success_notification = @{
title = “Success”;
value = “Deploy $OctopusProjectName release $OctopusReleaseNumber to $OctopusEnvironmentName”;
fallback = “Deployed $OctopusProjectName release $OctopusReleaseNumber to $OctopusEnvironmentName successfully”;
color = “good”;
Slack-Rich-Notification $hook_config $success_notification

And the error:

Invoke-Restmethod : The remote name could not be resolved: 'hooks.slack.com
At C:\Octopus\Work\20160627103714-70\Script.ps1:28 char:5

  • Invoke-Restmethod -Method POST -ContentType application/json -Body 

($payload …

  •   + CategoryInfo          : NotSpecified: (:) [Invoke-RestMethod], WebException
      + FullyQualifiedErrorId : System.Net.WebException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

The remote script failed with exit code 1


Thanks for reaching out. The error seems to indicate that the VM can’t reach hooks.slack.com. Have you tried doing a simple Ping hooks.slack.com? Try this first and let me know what happens.

The other thing I can think of is that the account currently running the Octopus server (which is the one that will execute this PS script) might have some kind a permissions issue. Is there any chance you can run the Octopus Server service with your own account and see if that works?