I have 5 environments to manage. I often have to bring couple of services down on few servers on different environments.
To handle this I created an xml with Environment details and its server details. Then created an xml object in my powershell script.
Script works fine on ISE but gives error on shell:
PS C:\Windows\system32> cd
PS C:> cd .\Power
PS C:\Power> cd .\RestoreAutomation
PS C:\Power\RestoreAutomation> .\StopServices.ps1
PS C:\Power\RestoreAutomation> Stop-Services -environment testlab
Stop-Services : The term ‘Stop-Services’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a pa
and try again.
At line:1 char:1
- Stop-Services -environment testlab
-
+ CategoryInfo : ObjectNotFound: (Stop-Services:String) [], CommandNotFoundException
Code is as follows:
Function Stop-Services{ [cmdletBinding()] param( [Parameter(Mandatory=$True)] [string]$Environment ) begin{ $EnvData = [xml] (cat C:\Power\RestoreAutomation\Env.xml) foreach($e in $EnvData.ADLAB.Environment){ if($e.Name -eq $Environment){ $Env = $e } } } Process{ #Stopping Joma Services Write-Verbose "Stopping Joma Services for $Environment Environment" Invoke-Command -ComputerName $Env.JomaServer {Stop-Service -Name "Vital JoMa Service" -Force} #Stopping Axapta Services Write-Verbose "Stopping Axapta Services for $Environment Environment" Invoke-Command -ComputerName $Env.AxaptaServer {Stop-Service -DisplayName "*Dynamics AX Object Server*" -Force} #Stopping ProInvest Services Write-Verbose "Stopping ProInvest Services for $Environment Environment" Invoke-Command -ComputerName $Env.ProInvest {Stop-Service -Name "*Proinvest*" -Force} #Stopping IIS AppPools Write-Verbose "Stopping IIS AppPools for $Environment Environment" Invoke-Command -ComputerName $Env.AppServer {IISRESET /STOP} #Stopping Biztalk Host Instances Write-Verbose "Stopping Biztalk Host Instances for $Environment Environment" Invoke-Command -ComputerName $Env.BiztalkServer {Stop-Service -DisplayName "*BizTalk Service BizTalk Group*" -Force} } End{} } Here is the xml: T00 T-115-270-022 T-115-270-023 T-115-270-042 T-115-270-043 T-115-270-034 T-115-270-035 ADLABGJOBZT14 ADLABGJOBZT15 ADLABGJOBZT16 ADLABGJOBZT17 TV-115-270-005 ADLABGJODAX11 ADLABGJODAX10 Testlab TESTLABJOMA TESTLABAPP TESTLABBZT TESTLABAPP TESTLABAPP
Also when I try to print the xml object value on the on the screen it just prints the type of an object. I tried this
Write-Verbose “Stopping Joma Services for $Environment Environment $Env.JomaServer”
I am a newbie to powershell. Any help will be appreciated :). Thanks in Advance!!