通过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的类型系统,以及管道.模块的概念等等.那 ...
随机推荐
- 强化学习---A3C
Asynchronous Advantage Actor-Critic (A3C) 在RL任务中,我们本质上最终要学习的是策略(Policy) value-based方法:间接方法,即通过学习值函数( ...
- 实战http切换成https
Server端使用Nginx + Tomcat Niginx SSL on Tomcat SSL non 步骤: 1.修改代码,将外部引用的http js css 文件修改为https,若外部链接不支 ...
- Struts2输入校验(XML方式)
本章主要介绍struts2的XML配置方式输入校验.以下将结合一个实例程序进行说明. 代码结构: 关键代码: RegistAction.javapackage com.alfred.regist.ac ...
- Android获取全局Context的方法
Android获取全局Context的方法 Android--应用全局获取Context - 超宇的博客 - CSDN博客https://blog.csdn.net/chaoyu168/article ...
- webStorm 2018 激活
原文地址 https://blog.csdn.net/jiangxinyu50/article/details/79104016 webStorm 2018 激活 今天早上一更新webStorm,之前 ...
- ajax处理文件下载
ajax中处理文件下载,可能大数会遇到我和一样的问题,什么问题呢?就是下载程序执行了,但是浏览器没有任何下载操作,这是为什么呢? 那是因为response原因,一般请求浏览器是会处理服务器输出的res ...
- Python读写docx文件
Python读写word文档有现成的库可以处理.我这里采用 python-docx.可以用pip install python-docx安装一下. 这里说一句,ppt和excel也有类似的库哦,而且是 ...
- Django框架----路由系统(详细)
Django的路由系统 Django 1.11版本 URLConf官方文档 URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL与要为该URL调用的视图函数之间的映射表. ...
- The Little Prince-11/28
The Little Prince-11/28 Today I find some beautiful words from the book. You know -- one loves the s ...
- 爬虫学习06用selenium爬取空间
用selenium爬取空间 from selenium import webdriver from lxml import etree import time pro = webdriver.Chro ...