我正在尝试使用powershell创建一个GUI页面。该脚本在Powershell 4.0中可以正常工作。但是尝试在poweshell 3.0版中执行时会抛出异常
$return = button "Enter Parameters" "Enter Domain" "Enter User" "Enter Server"
function button ($title,$domain, $user, $Server) {
[void][System.Reflection.Assembly]::LoadWithPartialName( "System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName( "Microsoft.VisualBasic")
$form = New-Object "System.Windows.Forms.Form";
$form.Width = 500;
$form.Height = 150;
$form.Text = $title;
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen;
$textLabel1 = New-Object "System.Windows.Forms.Label";
$textLabel1.Left = 25;
$textLabel1.Top = 15;
例外:
At C:\Users\rights.ps1:16 char:35
+ [void][System.Reflection.Assembly]LoadWithPartialName( System.Windows.Forms)
+ ~~~~~~~~~~~~~~~~~~~
Unexpected token 'LoadWithPartialName' in expression or statement.
At C:\Users\rights.ps1:17 char:35
+ [void][System.Reflection.Assembly]LoadWithPartialName( Microsoft.VisualBasic)
+ ~~~~~~~~~~~~~~~~~~~
Unexpected token 'LoadWithPartialName' in expression or statement.
At C:\Users\rights.ps1:23 char:67
+ $form.StartPosition = [System.Windows.Forms.FormStartPosition]CenterScreen;
+ ~~~~~~~~~~~~
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
To use methods in a namespace you need double quotes after the end of the ]. Ex. [System.Windows.Forms.FormStartPosition]::CenterScreen()