Function Unzip-File()
{
param([string]$ZipFile,[string]$TargetFolder)
if(!(Test-Path $TargetFolder))
{
mkdir $TargetFolder
}
$shellApp = New-Object -ComObject Shell.Application
$files = $shellApp.NameSpace($ZipFile).Items()
$shellApp.NameSpace($TargetFolder).CopyHere($files)
}
Remove-Item E:test123454* -recurse #删除文件夹下的所有文件,保留文件夹
Remove-Item E:test1.txt.txt #删除指定文件
Remove-Item E:test123454 -recurse #删除文件夹
Unzip-File -ZipFile E:a.zip -TargetFolder E:test
注:尽量不要解压到C盘,powershell脚本对C盘的操作容易出错
如果不行执行powershell 命令 需要运行set-executionpolicy -executionpolicy unrestricted
最后
以上就是谦让高跟鞋最近收集整理的关于powershell 脚本解压zip文件到指定目录的全部内容,更多相关powershell内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复