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

%3CLINGO-SUB%20id%3D%22lingo-sub-133480%22%20slang%3D%22en-US%22%3EPowerShell%20script%20for%20stop%20application%20in%20remote%20server%2C%20which%20is%20domain%20joined.%20Not%20workgrou%20server%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-133480%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20Team%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EI%20am%20working%20one%20of%20the%20customer%20enterprise%20environment%20azure%20cloud%20automation%20tasks.%20From%20azure%20perspective%20past%20couple%20of%20days%20working%20and%20trying%20to%20setup%20lot%20of%20things%20including%20Azure%20Runbook.%26nbsp%3B%3C%2FSPAN%3EI%20am%20trying%20to%20create%20a%20powershell%20script%2Fworkflow%20to%20place%20in%20Azure%20Runbooks%20and%20then%20execute.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20Runbook(script)%20will%20be%20scheduled%2C%20once%20executed%20it's%20need%20to%20stop%20running%20application%20inside%20remote%20server.%20The%20remote%20server%20is%20domain%20joined%20not%20an%20work%20group.%20Similar%20way%20in%20coming%20days%20decided%20to%20create%20disk%20space%20cleanup%20using%20script%20through%20Runbook.%20I%20have%20searched%20many%20articles%20and%20not%20able%20to%20find%20any%20sample%20scripts%20and%20there%20is%20no%20proper%20guidance%20with%20steps%20to%20follow%20and%20create.%20So%20can%20you%20please%20check%20and%20let%20me%20know%2C%20this%20kind%20of%20functionality%20is%20available%20in%20azure%20Runbooks%20or%20not%3F.%20If%20the%20answer%20is%20YES%20then%20share%20me%20exact%20scripts%20which%20ever%20available%20from%20your%20team.%3C%2FP%3E%0A%3CP%3EOtherwise%20share%20some%20ideas%20with%20sample%20commands%20to%20connect%20the%20machine%20and%20stop%20running%20application%20.exe.%26nbsp%3B%20Other%20one%20cleaning%20temporary%20files%20in%20C%3A%5C%20drive%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%20me%20know%20this%20post%20is%20not%20understandable%20or%20any%20clarification%20required.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%3C%2FP%3E%0A%3CP%3EJaga%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-133480%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAutomation%20and%20DSC%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-144973%22%20slang%3D%22en-US%22%3ERe%3A%20PowerShell%20script%20for%20stop%20application%20in%20remote%20server%2C%20which%20is%20domain%20joined.%20Not%20workgrou%20se%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-144973%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20is%20pretty%20straightforward%20to%20do%2C%20and%20I%20have%20implemented%20this%20as%20part%20of%20Azure%20self-healing%20and%20operations%20scripts%20in%20Azure%20Automation.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20need%20to%20look%20at%20leveraging%20PS%20Remoting%20to%20remote%20into%20the%20Azure%20VMs%20in%20your%20Subscription.%20Thereafter%2C%20you%20can%20execute%20specific%20scripts%20for%20various%20operations%20that%20you%20want%20to%20take%20place%20in%20one%20or%20more%20of%20those%20VMs%20like%20Disk%20Cleanup%2C%20Registry%20Cleanup%2C%20Checking%20on%20Windows%20Services%2C%20Stopping%20any%20specific%20processes%20(Killing%20them)%2C%20collect%20Antivirus%20logs%20to%20upload%20them%20on%20a%20storage%20location%2C%20do%20basic%20diagnostics%20check%20from%20inside%20the%20OS%20etc.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-141103%22%20slang%3D%22en-US%22%3ERe%3A%20PowerShell%20script%20for%20stop%20application%20in%20remote%20server%2C%20which%20is%20domain%20joined.%20Not%20workgrou%20se%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-141103%22%20slang%3D%22en-US%22%3E%3CP%3Elook%20into%20WinRM%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUse%20something%20like%20this%20to%20make%20the%20connection%20to%20the%20vm%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20don't%20know%20the%20names%20of%20the%20VM's%20you%20would%20use%20something%20like%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24vmList%20%3D%20get-AzureRmVm%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20to%20action%20something%20on%20those%20VMs%26nbsp%3B%3C%2FP%3E%0A%3CP%3EInlineScript%20%7B%3CBR%20%2F%3E%20%24options%20%3D%20New-PSSessionOption%20-SkipCACheck%3C%2FP%3E%0A%3CP%3EInvoke-Command%20-ConnectionUri%20%24Using%3AVMName%20-Credential%20%24Using%3AVMCredential%20-SessionOption%20%24options%20-ArgumentList%20%24Using%3AFolder%20%60%3CBR%20%2F%3E%20-ScriptBlock%20%7B%3CBR%20%2F%3E%20param%20(%5Bstring%5D%24folder)%20%3CBR%20%2F%3E%20mkdir%20%24folder%3CBR%20%2F%3E%20%7D%3CBR%20%2F%3E%20%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
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.