Common.ps1
cls; #Global is Public#script is Internal#script was Script#local is the current stack level#numbered scopes was from 0..N where each of the step is up to the stack level (and 0 is Local) $Script:P sscriptroot =split-path-parent $MyInvocation. mycommand.def Inition$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 { <span style= "white-space:pre" ></span> #your PS code<span style= "White-space:pre" ></span> $psversiontable |& $log <span style= "White-space:pre" ></span> $Script:p SS = PS <span style= "White-space:pre" ></span> $Script: i = 0<span style= "White-space:pre" ></span> foreach ($ps in $pss) <span style= "White-space:pre" ></span>{<span style= "White-space:pre" ></ Span>write-progress-activity "onProcessing ... "-status" $ps ... $ ($i. ToString () + '/' + $PSS. count.tostring ()) "-percentcomplete ($i ++/($PSS. Count) *100) <span style=" White-space: Pre "></span>sleep 1<span style=" White-space:pre "></span>}}catch {<span style=" White-space: Pre "></span>" at $ (get-date-format "YY-MM-DD HH:mm:ss") error occured:$_. Exception "|& $log}finally{<span style=" White-space:pre "></span>& $rem |& $log <span style= "White-space:pre" ></span> "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 "Choi Ce-> "if errorlevel 2 goto exit if errorlevel 1 goto GenA REM Generate append:genacls Echo starting Powershell,genera Te 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-nolo Go-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 Clea Ring Cachedsqlsrem PowersHell-file%cd%\module\clearcachedsqls.ps1-nologo-version%vers%-mtaecho finishedpause goto:entrancerem Set-Executio Npolicy-executionpolicy remotesigned:setpcls Echo set-executionpolicy-executionpolicy remotesignedpowershell-file% Cd%\module\set-executionpolicy.ps1-nologo-version%vers%-mtaecho finishedpause goto:entrancerem config:conf CLS EC Ho Configuring PowerShell inittial Parameters:echo Edit and save to Contiue.rem Echo editing%cd%\module\configrem Notepa D%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
Powershell Batch processing template