1

I'm trying to run the powershell script below in Micrososft Azure runbooks. However, I keep on getting the error:

error

The script is as follows:

#### Provide the computer name in $computername variable

$ServerName = "testauto","LocalHost","Server-2","Not-Exists", "Fake-computer", "Dc-1" 

##### Script Starts Here ###### 

foreach ($Server in $ServerName) {

            if (test-Connection -ComputerName $Server -Count 2 -Quiet ) { 

                  write-Host "$Server is alive and Pinging " -ForegroundColor Green

                              } else

                              { Write-Warning "$Server seems dead not pinging"

                              }      

}

The script runs ok within Powershell ISE, but not in Microsoft Azure Automation Runbooks.

Can someone please let me know why?

Cheers

Carlton

Sam Cogan
  • 38,736
  • 6
  • 78
  • 114
Carltonp
  • 171
  • 1
  • 3
  • 8
  • I've tested this out and get the same error. I would suspect there is some sort of restriction in Azure Automation that prevents this running, but I'm not clear on what yet. I assume you are running this on standard workers, not hybrid ones? – Sam Cogan Jan 08 '17 at 16:05
  • Hi Sam, thanks for responding..yes, I running on standard workers, not hybrid ones – Carltonp Jan 08 '17 at 16:35
  • Sam, the problem that was occurring with the link from the site you provided was due to administrator wanting to connect to on-premise site. My situation is within the same Vnet. – Carltonp Jan 09 '17 at 14:32
  • @MichaelBrown did you mean to direct that at @carltonp? – Sam Cogan Jan 09 '17 at 14:35
  • @Sam Cogan, yes I did sorry. – Michael Brown Jan 09 '17 at 14:54

1 Answers1

0

The Test-Connection is not installed in Azure Automation by default, so you could not use the cmdlet.

You could import a module from the Automation Module Gallery with the Azure portal. More information please refer to this article.

Shui shengbao
  • 3,583
  • 1
  • 11
  • 20
  • Walter, thanks for the link. I had been checking that out. Unfortunately, the resolution wasn't to be found on that site – Carltonp Jan 09 '17 at 14:17
  • The problem appears to be with this line of code: RunbookFlow : The specified service does not exist as an installed service. (Exception from HRESULT: 0x80070424) At line:7 char:57 – Carltonp Jan 09 '17 at 14:28
  • @Carltonp I update my answer. I test in my lab. It works for me. – Shui shengbao Jan 10 '17 at 06:20
  • Hi Walter, this is looking promising. I can't test at the moment as I'm having a problem with my azure account. As soon as its fixed I'll try the solution. Cheers – Carltonp Jan 10 '17 at 13:27
  • Hi Walter, I have finally got my account working. Going to try your suggestion now.. I will keep you posted. Cheers – Carltonp Jan 10 '17 at 19:34
  • Hi Walter, I have the AzureRM.Websites, and I found the cmdlet Test-Connection, but I still get the error message : test-Connection : The specified service does not exist as an installed service I'm not sure how you managed to get it working – Carltonp Jan 10 '17 at 20:10
  • @Carltonp Sorry for my mistake, I test other cmdlet `Set-AzureRmAppServicePlan` , it works. Just recentlyI, test `Test-Connection`, it does not work for me too. Maybe you could try to use `TestConnectionAsync `. – Shui shengbao Jan 11 '17 at 01:47