PowerShell script for stop application in remote server, which is domain joined. Not workgrou server

Deleted
Not applicable

Hello Team,

 

I am working one of the customer enterprise environment azure cloud automation tasks. From azure perspective past couple of days working and trying to setup lot of things including Azure Runbook. I am trying to create a powershell script/workflow to place in Azure Runbooks and then execute.

 

The Runbook(script) will be scheduled, once executed it's need to stop running application inside remote server. The remote server is domain joined not an work group. Similar way in coming days decided to create disk space cleanup using script through Runbook. I have searched many articles and not able to find any sample scripts and there is no proper guidance with steps to follow and create. So can you please check and let me know, this kind of functionality is available in azure Runbooks or not?. If the answer is YES then share me exact scripts which ever available from your team.

Otherwise share some ideas with sample commands to connect the machine and stop running application .exe.  Other one cleaning temporary files in C:\ drive,

 

Let me know this post is not understandable or any clarification required.

 

Thanks

Jaga

2 Replies

look into WinRM 

Use something like this to make the connection to the vm 

 

If you don't know the names of the VM's you would use something like 

 

$vmList = get-AzureRmVm 

 

Then to action something on those VMs 

InlineScript {
$options = New-PSSessionOption -SkipCACheck

Invoke-Command -ConnectionUri $Using:VMName -Credential $Using:VMCredential -SessionOption $options -ArgumentList $Using:Folder `
-ScriptBlock {
param ([string]$folder)
mkdir $folder
}
}

 

 

This is pretty straightforward to do, and I have implemented this as part of Azure self-healing and operations scripts in Azure Automation. 

 

You need to look at leveraging PS Remoting to remote into the Azure VMs in your Subscription. Thereafter, you can execute specific scripts for various operations that you want to take place in one or more of those VMs like Disk Cleanup, Registry Cleanup, Checking on Windows Services, Stopping any specific processes (Killing them), collect Antivirus logs to upload them on a storage location, do basic diagnostics check from inside the OS etc.