1

我写了一个脚本来显示一个消息框。它在 PowerShell 5 中运行良好,但在 PowerShell 6 中不运行。我怎样才能使它工作?

我写的脚本(摘录):

function test
{
     [CmdletBinding()]
     param([Parameter(Mandatory = $true, Position = 0)][string]$directory)

     Add-Type -AssemblyName System.Windows.Forms
     Add-Type -AssemblyName Microsoft.Visualbasic
     Add-Type -AssemblyName System.Drawing

  #----------------------------
}

错误信息:

添加类型:找不到路径“C:\Users\Owner\System.Windows.Forms.dll”,因为它不存在。在 C:\Users\Owner\Desktop\sample\trans-search.ps1:8 char:6 + Add-Type -AssemblyName System.Windows.Forms + ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\Owner\System.Windows.Forms.dll:String) [添加类型],ItemNotFoundException + FullyQualifiedErrorId:PathNotFound,Microsoft.PowerShell.Commands.AddTypeCommand

谢谢您的帮助。

4

1 回答 1

2

这些类型在 PowerShell 6.x 中不可用。它们应该在 PowerShell v7 中可用,但不在预览版 2 中

于 2019-07-26T13:06:31.137 回答