Powershell 批處理模板,powershell批處理

來源:互聯網
上載者:User

Powershell 批處理模板,powershell批處理

common.ps1

cls; #Global is public#Script is internal#Script is Script#Local is current stack level#Numbered scopes are from 0..N where each step is up to stack level (and 0 is Local)$Script:PSScriptRoot =Split-Path -Parent $MyInvocation.MyCommand.Definition$Script:strDate = Get-Date -Format "yyyyMMdd"#logging path and method$Script:logfile = "$PSScriptRoot\log$($strDate).txt"$Script:log = {$input|Tee-Object -FilePath $logfile -Append}#commen$Script:rem = {$Script:i = '';1..75|%{$i += '-'};$i } #start&$rem|&$logtry{ #your ps code$psversiontable|&$log $Script:pss = ps$Script:i = 0foreach ($ps in $pss){Write-Progress -Activity "on processing..." -status "$ps...$($i.tostring() + '/' + $pss.count.tostring())" -percentcomplete ($i++/($pss.count)*100)sleep 1}}catch {"At $(Get-Date -Format “yy-MM-dd HH:mm:ss”) error occured:$_.Exception"|&$log}finally{&$rem|&$log"Finish deploying at $(Get-Date -Format “yy-MM-dd HH:mm:ss”)"|&$log }notepad "$logfile"


start.bat

@echo off  @cd %cd%@set vers=2.0:Entrance  cls   goto Start  :Start  title APOMS SQL Deployment Guide   echo Please select an option from the list with the corresponding key  echo ---------------------------------------------------------------- echo [1] Test  echo [2] Exit echo ----------------------------------------------------------------  CHOICE /c 12 /M "Choice->" if errorlevel 2 GOTO exit if errorlevel 1 GOTO GenA  rem Generate Append:GenAcls  echo starting powershell,Generate Appendpowershell -file %cd%\common.ps1 -nologo -version %vers% -Mtaecho finishedrem timeout 2  pausegoto :Entrance rem Generate Merge :GenMcls   echo starting powershell,Generate Merge rem powershell -file %cd%\module\GenerateMerge.ps1 -nologo -version %vers% -Mtaecho finishedpausegoto :Entrancerem Depoly:Depo cls  echo Caching sqlcmd files to local.powershell -file %cd%\Mail\Send-AvEmail.ps1 -nologo -version %vers% -Mtaecho finishedpausegoto :Entrancerem clear:cleacls  echo clearing CachedSQLSrem powershell -file %cd%\module\ClearCachedSQLS.ps1 -nologo -version %vers% -Mtaecho finishedpause  goto :Entrancerem Set-ExecutionPolicy -ExecutionPolicy remotesigned:setPcls  echo Set-ExecutionPolicy -ExecutionPolicy remotesignedpowershell -file %cd%\module\Set-ExecutionPolicy.ps1 -nologo -version %vers% -Mtaecho finishedpause  goto :Entrancerem Config :Conf cls   echo configuring powershell inittial parameters:echo edit and save to contiue.rem echo editing  %cd%\module\configrem notepad %cd%\module\configecho editing  %cd%\module\config_sysnotepad "%cd%\module\config_sys"echo testing config_syspowershell -file %cd%\module\TestConfig.ps1 -nologo -version %vers% -Mtapausegoto :Entrancerem Help:Helpcls  @type %cd%\module\help.txtpause  goto :Entrancerem SqlCMD:SqlCcls  powershell -file %cd%\module\GenerateSqlcmdFiles-force.ps1 -nologo -version %vers% -Mtapause  goto :Entrancerem default:N  cls  echo Invalid Selection! Try again  @type %cd%\module\help.txtpause  goto :Entrance rem exit:Exit exit


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.