Stop a remote service running in linux server using powershell runbook in azure

Perumal, Janakiraman 246 Reputation points
2020-11-08T15:08:55.467+00:00

Hi Team,

I need to stop a application service running on a Linux server from PowerShell runbook in azure. Is there a way to use ssh keys to login and create New-PSSession session?

After stopping the application, i need to run another runbook. What is the best way to achieve this?

Thanks in advance.

Regards,
Janakiraman

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,255 questions
{count} votes

Accepted answer
  1. Perumal, Janakiraman 246 Reputation points
    2020-11-26T00:35:31.513+00:00

    Hi Andreas,

    I have invoked API calls to execute a remote command/script using the below steps. It worked for me.. thanks for your support.

    https://blog.tekspace.io/access-azure-rest-api-using-powershell/

    Regards,
    Janakiraman

    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 108.7K Reputation points MVP
    2020-11-08T15:38:39.667+00:00

    Maybe this is helpful:
    https://azure.microsoft.com/de-de/blog/managing-ssh-enabled-linux-hosts-with-azure-automation/


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  2. Perumal, Janakiraman 246 Reputation points
    2020-11-09T13:26:12.71+00:00

    Hi Anderas,

    I am getting the below error, not sure if my automation account needs any additional module or any setup at the target end. Can you please advice.

    Invoke-AutomationSshCommand : The term 'Invoke-AutomationSshCommand' is not recognized as the name of a cmdlet,
    function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
    path is correct and try again.
    At line:12 char:2

    • Invoke-AutomationSshCommand
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : ObjectNotFound: (Invoke-AutomationSshCommand:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

    Regards,
    Janakiraman.

    0 comments No comments

  3. Andreas Baumgarten 108.7K Reputation points MVP
    2020-11-09T18:14:15.007+00:00

    It looks like the right module is not added to the Automation Account. For that reason you get a "Invoke-AutomationSshCommand is not recognized as the name of a cmdlet".

    In the link I posted above is a PowerShell module linked:
    https://gallery.technet.microsoft.com/scriptcenter/SSH-PowerShell-Module-17616e1a

    There are a few SSH Powershell modules for SSH around in the PowerShell Gallery as well:
    https://www.powershellgallery.com/packages?q=ssh

    And third option: In the Automation Account -> Module Gallery are different SSH PowerShell modules available as well (search for "SSH" without the quotes)


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

  4. Perumal, Janakiraman 246 Reputation points
    2020-11-11T11:33:49.7+00:00

    Hello Andreas,

    For some reason i am not able to figure out how to pass invoke a command/script or enter a session within powershell to my remote linux machine running in azure.

    I am quite new to this, so i tried my level best but couldn't.

    I have raised an ticket with microsoft and they are suggesting for Linux hybrid worker. I am in mid of deploying that solution, however i am getting an error there as well.

    Its throws an error of unsupported runbook. The same is running fine if i use azure sandbox.

    would you mind to share an sample command to for the SSH?

    Regards,
    Janakiraman

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.