添加类型:找不到命令

Add-Type: command not found

我正在尝试为 PowerShell 创建一个基本的 GUI,但由于某种原因它无法识别 Add-Type 范围。 这是我使用的代码:

# Init PowerShell Gui
Add-Type -AssemblyName System.Windows.Forms

# Create a new form
$LocalPrinterForm                    = New-Object system.Windows.Forms.Form

# Define the size, title and background color
$LocalPrinterForm.ClientSize         = '500,300'
$LocalPrinterForm.text               = "LazyAdmin - PowerShell GUI Example"
$LocalPrinterForm.BackColor          = "#ffffff"

# Display the form
[void]$LocalPrinterForm.ShowDialog()

当 运行 它与:$ ./exampleScript.ps1

我得到:./exampleScript.ps1: line 2: Add-Type: command not found

这可能是什么问题?

add-type 命令对我来说工作正常我有版本 5.1.18362.628

要查找您的 PowerShell 版本,请键入以下命令:

$PSVersionTable