如何编写下面的power shell脚本 [英] How to write power shell script for below
问题描述
Hi, 这篇关于如何编写下面的power shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
这是sathish作为构建和发布自动化开发人员工作。
我有一个场景,我想写下面的power shell脚本。
1)为阵列分配多个服务器和服务。
2)停止特定的服务我们在数组中使用的服务器。
3)如果路径中存在文件,我们应该删除那些文件并复制新文件。
4)启动服务我们之前停了下来。
以下是脚本...但这不起作用...
任何人都可以帮助我脚本。
<前lang =C#>#服务器信息
Arrayofservers =数组(服务器)
Foreach(Eachserverinfo Arrayofservers中的class =code-keyword> {
write-host \ r $ EachserverInfo;
Arrayofservices = Array(Services)
Foreach(在 Arrayofservices中的Eachserviceinfo ){
write-host \ rr $ EachserviceInfo;
get-service -computername $ SvrName -name $ services | $ {
$ SvrName上的写主机 $($ _。name)是$ ($ _。status)
If($ _。status -eq ' stopped' ){
写主机 启动$($ _。name)......
写主机 $($ _。name)已启动
$ _.Start()}
elseIf($ _。status -eq ' running' ){
写主机 停止$($ _。name)......
写主机 $($ _。name)已停止
$ _。停止()}
}
#Copy可部署到服务器的项目
write-host 复制文件:$ Env到$ BasePath / $ Env /
复制项 $ sourcepath $ Targetpath -Force;
$ SvrName上的写主机 $($ _。name)是$($ _。status)
If($ _。status -eq ' 停止'){
写主机 启动$($ _。name).. 。
写主机 $($ _。name)已启动
$ _。开始()}
elseIf($ _。status -eq ' 运行'){
写主机 停止$($ _。name).. 。
写主机 $($ _。name)已停止
$ _。停止()}
}
}
}
谢谢,sathish
我尝试过:
1)为阵列分配多个服务器和服务。
2)停止我们在阵列中使用的特定服务器上的服务。
3)如果路径中存在文件,我们应该删除这些文件并复制新文件。
4)启动之前停止的服务。 EachserverInfo;
Arrayofservices中的Eachserviceinfo ){
Arrayofservices = Array(Services)
Foreach(在
write-host \ rr
EachserviceInfo;
get-service -computername
SvrName -name
This is sathish working as build and release automation developer.
I have a scenario, that i want to write power shell script for the below.
1) Assigning multiple servers and services for an array.
2) Stop the services on the specific servers we are taking in the array.
3) If files are exist in the path, we should delete that files and Copy new Files.
4) Start the services which we stopped before.
below is the script...but this is not working...
can any one help me out with the script.
# Info of Servers
Arrayofservers = Array(Servers)
Foreach(Eachserverinfo in Arrayofservers) {
write-host "\r" $EachserverInfo;
Arrayofservices = Array(Services)
Foreach(Eachserviceinfo in Arrayofservices) {
write-host "\r" $EachserviceInfo;
get-service -computername $SvrName -name $services | % {
Write-host "$($_.name) on $SvrName is $($_.status)"
If ($_.status -eq 'stopped') {
Write-host "Starting $($_.name) ..."
Write-host "$($_.name) is started"
$_.Start()}
elseIf ($_.status -eq 'running') {
Write-host "Stopping $($_.name)..."
Write-host "$($_.name) is stopped"
$_.Stop() }
}
#Copy Deployable Items to the Server
write-host "Copying File: $Env to $BasePath/$Env/"
Copy-Item "$sourcepath" "$Targetpath" -Force;
Write-host "$($_.name) on $SvrName is $($_.status)"
If ($_.status -eq 'stopped') {
Write-host "Starting $($_.name) ..."
Write-host "$($_.name) is started"
$_.Start()}
elseIf ($_.status -eq 'running') {
Write-host "Stopping $($_.name)..."
Write-host "$($_.name) is stopped"
$_.Stop() }
}
}
}
Thanks, sathish
What I have tried:
1) Assigning multiple servers and services for an array.
2) Stop the services on the specific servers we are taking in the array.
3) If files are exist in the path, we should delete that files and Copy new Files.
4) Start the services which we stopped before.EachserverInfo;
Arrayofservices = Array(Services)
Foreach(Eachserviceinfo in Arrayofservices) {
write-host "\r"
EachserviceInfo;
get-service -computername
SvrName -name