通过cmd调用Powershell脚本
一共需要3个文件,把这3个文件放在一个路径下
UTF8NoBOM.bat 这个文件是为了调用ps1
pwsh -file "%cd%\UTF8NoBOM.ps1"
UTF8NoBOM.ps1 这个文件是为了导入自定义的module,使用自定义module中定义的Powershell函数
Import-Module ".\UTF8NoBOM.psm1"
$extension = "*.sql"
Convert-EncodingToUTF8NoBOM "..\..\文件夹1" "$extension"
Convert-EncodingToUTF8NoBOM "..\..\文件夹2" "$extension"
Convert-EncodingToUTF8NoBOM "..\..\文件夹3" "$extension"
UTF8NoBOM.psm1 自定义的module
function Convert-EncodingToUTF8NoBOM {
param(
[Parameter(Mandatory = $false)]
[string]
$targetDir = '.',
[Parameter(Mandatory = $false)]
$extension = '*')
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
$files = Get-ChildItem -Path $targetDir -Filter $extension
foreach ($file in $files)
{
#$file.FullName
$fileContent = Get-Content -Path $file.FullName
[System.IO.File]::WriteAllLines($file.FullName,$fileContent,$Utf8NoBomEncoding)
}
}
通过cmd调用Powershell脚本的更多相关文章
- C#调用PowerShell脚本
今天通过一个小例子,学习了C#如何调用PowerShell脚本文件的Function以及传参. private bool CallPowershell(string outputFile) { str ...
- 在Bat批处理中调用Powershell脚本
##如何在BAT中调用powershell,把下面代码另存为bat格式pushd %~dp0powershell.exe -command ^ "& {set-executionp ...
- cmd命令调用powershell脚本方法
cmd方法: powershell -command ". ('ps1脚本路径'); WriteInfo -param 'param参数值'" ps1脚本代码: function ...
- 怎样从 bat 批处理文件调用 PowerShell 脚本
https://stackoverflow.com/questions/19335004/how-to-run-a-powershell-script-from-a-batch-file https: ...
- 【黑客基础】Windows PowerShell 脚本学习(上)
视频地址:[黑客基础]Windows PowerShell 脚本学习 2019.12.05 学习笔记 1.$PSVersionTable :查看PowerShell的版本信息. 2.PowerShel ...
- 如何在windows计划中调用备份sharepoint2010网站集的powershell脚本
最近有个项目需要在在windows计划中使用powershell脚本备份sharepoint2010网站集,打开sharepoint的powershell执行命令管理界面的属性 查看: C:\Wind ...
- powershell脚本执行绕过powershell下脚本执行限制(cmd下执行)以及在cmd下隐藏脚本窗口
powershell脚本执行绕过powershell下脚本执行限制(cmd下执行) powershell脚本运行方式有两种,一种是powshell中运行,另一种是在cmd中(在某些情况下相当有用) p ...
- 【Azure Developer】调用SDK的runPowerShellScript方法,在Azure VM中执行PowerShell脚本示例
当需要通过代码的方式执行PowerShell脚本时,可以参考以下的示例. Azure SDK中提供了两个方法来执行PowerShell脚本 (SDK Source Code: https://gith ...
- 在PowerShell脚本中集成Microsoft Graph
作者:陈希章 发表于2017年4月23日 我旗帜鲜明地表态,我很喜欢PowerShell,相比较于此前的Cmd Shell,它有一些重大的创新,例如基于.NET的类型系统,以及管道.模块的概念等等.那 ...
随机推荐
- Lua用table模拟二维数组
local array = {}; , , , , } , , , , } local row3 = {"I", "love", "lua" ...
- C-Cow Sorting (置换群, 数学)
Farmer John's N (1 ≤ N ≤ 10,000) cows are lined up to be milked in the evening. Each cow has a uniqu ...
- 英文名为什么最好不用joe?JOE英文名的寓意是什么?
英文名为什么最好不用joe?JOE英文名的寓意是什么? Joe 的意思是乔,人名.意为,上帝还会赐予 Joe 乔(男子名, 对不相识者非正式的称呼; Joseph的昵称)(=GIJoe)[美俚]美国兵 ...
- GUI相应鼠标事件
function varargout = GUI18(varargin) % GUI18 MATLAB code for GUI18.fig % GUI18, by itself, creates a ...
- The Little Prince-summary
The Little Prince-summary 这些年 ”寂寞”这个词使用频率越来越高 这些年 不管有钱没钱 有对象没对象的人 入夜时分总是心里空空 不知生活的意义是什么 我们不喜欢一座城市 对一 ...
- Kattis之旅——Rational Arithmetic
Input The first line of input contains one integer, giving the number of operations to perform. Then ...
- Pytorch的torch.cat实例
import torch 通过 help((torch.cat)) 可以查看 cat 的用法 cat(seq,dim,out=None) 其中 seq表示要连接的两个序列,以元组的形式给出,例如:se ...
- postman5.0.2_0+postmanInterceptor0.2.22_0下载安装,可发送header头 cookie 参数
Postman是chrome上一个非常好用的http客户端插件,可惜由于chrome安全的限制,发不出带cookie的请求.如果想要发送带cookie的请求,需要开启Interceptor 安装方法: ...
- 判断PC或mobile设备
js 限制: <script type="text/javascript"> function uaredirect(f){try{if(document.getEle ...
- python的zipfile、tarfile模块
zipfile.tarfile的用法 先占个位置,后续再实际操作和补充 参考 https://www.cnblogs.com/MnCu8261/p/5494807.html