Saturday, March 5, 2016

Powershell working on remote process and web service/server

$user = 'abc\testadmin'
$pass = 'passtest'
$login = New-Object System.Management.Automation.PSCredential -ArgumentList @($user,(ConvertTo-SecureString -String $pass -AsPlainText -Force))

#in below code we are bypassing excution policy to prevent popup
Invoke-Command -ComputerName testcomputer123 -ScriptBlock {set-executionpolicy bypass –force;\\testcomputer123\execfiles\stopkill.ps1} -Credential $login


#In stopkill.ps1 we will write below code to start and stop website,not only website we can even kill any process or and service even shutdown machine

#stopkill.ps1
Import-Module WebAdministration
kill -Name "TestASPDOTNET_DUMMY_Service" -Force
stop-website -Name "Default web Site"
start-website -Name "Default web Site"

No comments:

Post a Comment

Thanks for showing interest in tech-jockey.

Content of this blog has been moved to GITHUB

Looking at current trends and to make my content more reachable to people, I am moving all the content of my blog https://tech-jockey.blogsp...