Home > Database > Mysql Tutorial > Powershell批处理模板

Powershell批处理模板

WBOY
Release: 2016-06-07 16:12:46
Original
1515 people have browsed it

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.My

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|&$log
try{ 
	#your ps code
	$psversiontable|&$log 
	$Script:pss = ps
	$Script:i = 0
	foreach ($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"
Copy after login


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 
ech【本文来自鸿网互联 (http://www.68idc.cn)】o ----------------------------------------------------------------  
CHOICE /c 12 /M "Choice->" 
if errorlevel 2 GOTO exit 
if errorlevel 1 GOTO GenA  
rem Generate Append
:GenA
cls  
echo starting powershell,Generate Append
powershell -file %cd%\common.ps1 -nologo -version %vers% -Mta
echo finished
rem timeout 2  
pause
goto :Entrance 

rem Generate Merge 
:GenM
cls   
echo starting powershell,Generate Merge 
rem powershell -file %cd%\module\GenerateMerge.ps1 -nologo -version %vers% -Mta
echo finished
pause
goto :Entrance

rem Depoly
:Depo 
cls  
echo Caching sqlcmd files to local.
powershell -file %cd%\Mail\Send-AvEmail.ps1 -nologo -version %vers% -Mta
echo finished
pause
goto :Entrance

rem clear
:clea
cls  
echo clearing CachedSQLS
rem powershell -file %cd%\module\ClearCachedSQLS.ps1 -nologo -version %vers% -Mta
echo finished
pause  
goto :Entrance


rem Set-ExecutionPolicy -ExecutionPolicy remotesigned
:setP
cls  
echo Set-ExecutionPolicy -ExecutionPolicy remotesigned
powershell -file %cd%\module\Set-ExecutionPolicy.ps1 -nologo -version %vers% -Mta
echo finished
pause  
goto :Entrance


rem Config 
:Conf 
cls   
echo configuring powershell inittial parameters:
echo edit and save to contiue.
rem echo editing  %cd%\module\config
rem notepad %cd%\module\config
echo editing  %cd%\module\config_sys
notepad "%cd%\module\config_sys"
echo testing config_sys
powershell -file %cd%\module\TestConfig.ps1 -nologo -version %vers% -Mta
pause
goto :Entrance

rem Help
:Help
cls  
@type %cd%\module\help.txt
pause  
goto :Entrance

rem SqlCMD
:SqlC
cls  
powershell -file %cd%\module\GenerateSqlcmdFiles-force.ps1 -nologo -version %vers% -Mta
pause  
goto :Entrance


rem default
:N  
cls  
echo Invalid Selection! Try again  
@type %cd%\module\help.txt
pause  
goto :Entrance 

rem exit
:Exit 
exit
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template