powershell - 从 PowerShell 将布尔值传递给 .net 函数
问题描述
我需要调用该方法ZipFile.ExtractToDirectory
以在 PowerShell 中提取 zip 文件。当我尝试使用以下方法调用它时:[System.IO.Compression.ZipFile]::ExtractToDirectory($source, $destinationPath, $True)
我收到一条错误消息Cannot convert argument "entryNameEncoding", with value: "True", for "ExtractToDirectory" to type "System.Text.Encoding": "Cannot convert value "True" to type "System.Text.Encoding". Error: "Invalid cast from 'System.Boolean' to 'System.Text.Encoding'.""
我也尝试使用创建一个新的布尔变量[Boolean]$b = $true;
,然后传递它,但它仍然给出相同的错误。如果目标中存在文件,我如何传递true
值以覆盖文件?
Note:
我无法使用Expand-Archive
cmdlet,因为它仅受 PS V5.0 支持。我需要我的脚本在 PS4.1 上运行
如果文件夹存在,我也可以删除它然后提取,但想使用现有的。
解决方案
推荐阅读
- javafx - 将 java fx 代码转换为 java scenebuilder
- css - 我如何正确使用引导程序混合进行框阴影和过渡?
- android - 如何将 content:// uri 转换为文件路径?
- javascript - 如何获取“while”循环内的按钮的动态id属性?
- javascript - 有没有办法重构和简化这个服务器端代码?
- xml - 如何防止序列化程序用 CDATA 包围字符串
- javascript - TypeError: Invalid Locator while using contains() in xpath
- java - 为什么我的日期时间解析尝试失败?
- php - MySQL如何在使用除法时保持精度?
- ios - ios createTransactionRequest 中授权的.net 支付网关