search
HomeDatabaseMysql TutorialPowershell批处理模板
Powershell批处理模板Jun 07, 2016 pm 04:12 PM
cpowershellBatch processingtemplate

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"


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


Statement
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
无法删除在系统中打开的 ISO 文件:如何修复无法删除在系统中打开的 ISO 文件:如何修复Apr 16, 2023 pm 02:25 PM

什么是 ISO 文件?ISO 文件是一种包含光盘(例如 DVD 或 CD)的精确副本的文件。这种类型的光盘映像可以安装在您的计算机上,看起来就像您的计算机上连接了一个光驱,光驱中插入了包含数据的 CD 或 DVD。ISO 文件还可用于刻录创建它们的 DVD 或 CD 的新副本,或者只是将大量文件包含在一个易于下载的单个文件中。ISO 文件通常相当大;用完它们后,您很可能会想将它

如何在 Windows 11 上以管理员身份打开 PowerShell如何在 Windows 11 上以管理员身份打开 PowerShellMay 10, 2023 pm 06:40 PM

如何在Windows11上以管理员身份打开PowerShell以提升或管理员级别的权限运行PowerShell允许您运行绕过Windows文件保护的命令,例如用于Windows安装文件的命令。您可以通过直接打开PowerShell或打开新的Windows终端应用程序来运行PowerShell,该应用程序默认使用PowerShell运行命令。在Windows11上以管理员身份打开PowerShell:打开开始菜单并输入powershell或terminal。从右侧的

修复:Windows 11/10 中无法打开 PowerShell 或 PowerShell 已停止工作问题修复:Windows 11/10 中无法打开 PowerShell 或 PowerShell 已停止工作问题Apr 24, 2023 pm 07:49 PM

许多用户报告了WindowsPowerShell停止工作或根本无法打开的问题。看到PowerShell已停止工作消息的最常见原因之一是您的计算机上存在隐藏病毒。这反过来会减慢您的系统速度,并且系统上的其他进程将停止运行。该错误消息未提供有关此问题原因的任何信息,因此难以解决。如果您对PowerShell无法在您的PC上运行或打开问题感到恼火,那么本文适合您。在本文中,我们讨论了一些可用于修复此错误的解决方案。修复1–禁用和重新启用WindowsPowerShell1.使用Ctr

PowerShell渗透测试利器Nishang怎么用PowerShell渗透测试利器Nishang怎么用May 13, 2023 am 10:58 AM

初始PowerShell,首先我们先来了解一下概念:PowerShell可以当做是cmd(bat脚本语言)的升级版,它是Windows平台上的脚本语言。是面向对象,是和.NetFrameWork密切相关的。也可以认为是Windows上的bashshell。WindowsPowerShell是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用.NETFramework的强大功能。它引入了许多非常有用的新概念,从而进一步扩展了您在Windows命令提示符和WindowsHost环境中获得

PowerShell 部署失败并出现 HRESULT 0x80073D02 问题修复PowerShell 部署失败并出现 HRESULT 0x80073D02 问题修复May 10, 2023 am 11:02 AM

您在运行脚本时是否看到此错误消息“Add-AppxPackage:部署失败,HRESULT:0x80073D02,无法安装该包,因为它修改的资源当前正在使用中。PowerShell中出现错误0x80073D02…”?如错误消息所述,当用户在前一个进程运行时尝试重新注册一个或所有WindowsShellExperienceHost应用程序时,确实会发生这种情况。我们已经获得了一些简单的解决方案来快速解决这个问题。修复1–终止体验主机进程您必须在执行powershell命令之前结束

如何在 Windows 11 上安装和使用 Git如何在 Windows 11 上安装和使用 GitMay 28, 2023 am 08:08 AM

点击进入:ChatGPT工具插件导航大全Git是最流行的版本控制系统之一,它允许您跟踪对文件所做的所有更改,以便在需要时可以轻松恢复到早期版本。Git允许您同时拥有本地存储库和远程存储库,鼓励其他人协作并将所有这些更改集中到一个源。在Windows11上安装Git的先决条件在我们开始之前,有一些在Windows上安装Git的先决条件。他们来了:您的Windows帐户的管理员权限访问命令行工具(例如CMD或PowerShell)Git的用户名和密码(可选)你最喜欢的文本编辑器WSL上的Ubuntu

如何在 Windows 11 上启用管理员帐户如何在 Windows 11 上启用管理员帐户Apr 15, 2023 pm 07:46 PM

如何使用PowerShell在Windows11上启用或禁用管理员帐户在Windows11上启用管理员帐户的最快方法之一是使用PowerShell。您还可以使用较新的Windows终端,或者,如果您愿意,也可以使用较旧的命令提示符(cmd)工具。您需要确保从已经具有管理员权限的用户帐户运行这些命令。如果您使用的是标准用户帐户,则需要切换到另一个用户帐户才能运行此工具。要在Windows11上使用PowerShell启用管理员帐户:通过单击开始按钮或按Windows键打开

powershell和cmd的区别是什么powershell和cmd的区别是什么Jan 11, 2023 pm 02:23 PM

区别:1、运行Cmd时,只需占用不到1M的内存;而用PowerShell时,需要占用大约20M的内存。2、Cmd不支持语法高亮,PowerShell支持。3、用Cmd运行一些较为复杂、较为耗时的命令时,随意拖动命令行窗口时,窗口中的内容依然能够保持原样;但PowerShell不行。4、Cmd只能不能使用.net库中的命令,也不能使用Linux命令;而PowerShell可以。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.