Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
System.Management.Automation.ExitException:Powershell Studio中的系统错误_Powershell_Powershell Studio - Fatal编程技术网

System.Management.Automation.ExitException:Powershell Studio中的系统错误

System.Management.Automation.ExitException:Powershell Studio中的系统错误,powershell,powershell-studio,Powershell,Powershell Studio,我在Powershell中编写了一个脚本:导入CSV文件时,我想检查用户是否已经存在。以下是脚本: $wshell = New-Object -ComObject Wscript.Shell $adusers = Get-ADUser -SearchBase "DC=KOJ,DC=NL" -Filter * | Select-Object -ExpandProperty SamAccountName $UserList = Import-Csv -Path $txt_csv.Text

我在Powershell中编写了一个脚本:导入CSV文件时,我想检查用户是否已经存在。以下是脚本:

$wshell = New-Object -ComObject Wscript.Shell

$adusers = Get-ADUser -SearchBase "DC=KOJ,DC=NL" -Filter * |
    Select-Object -ExpandProperty SamAccountName

$UserList = Import-Csv -Path $txt_csv.Text -Delimiter ";" |
    Select-Object -ExpandProperty UPN

$exist = Compare-Object $adusers $Userlist -IncludeEqual -ExcludeDifferent |
    Select-Object -ExpandProperty InputObject

$flag = 0

foreach ($user in $exist) {         
    $flag = 1           
    $a = $wshell.Popup("$user exist make unique!", 0, "stop", 0x1)          
    Write-Host $user "already exists"           
}

if ($flag -eq 1) {          
    $form.Close()
    exit
}
当用户已经存在时,我会收到以下错误:

************** Exception Text **************
System.Management.Automation.ExitException: System error.
   at System.Management.Automation.Interpreter.ThrowInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   at System.Management.Automation.DlrScriptCommandProcessor.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
   at System.Management.Automation.DlrScriptCommandProcessor.Complete()
   at System.Management.Automation.CommandProcessorBase.DoComplete()
   at System.Management.Automation.Internal.PipelineProcessor.DoCompleteCore(CommandProcessorBase commandRequestingUpstreamCommandsToStop)
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary`2 functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args)
   at System.Management.Automation.ScriptBlock.<>c__DisplayClassa.<InvokeWithPipe>b__8()
   at System.Management.Automation.Runspaces.RunspaceBase.RunActionIfNoRunningPipelinesWithThreadCheck(Action action)
   at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, Dictionary`2 functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args)
   at System.Management.Automation.ScriptBlock.InvokeAsDelegateHelper(Object dollarUnder, Object dollarThis, Object[] args)
   at lambda_method(Closure , Object , EventArgs )
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
*************异常文本**************
System.Management.Automation.ExitException:系统错误。
at系统。管理。自动化。解释器。ThrowInstruction。运行(解释器框架)
在System.Management.Automation.Translator.EnterTryCatchFinallyInstruction.Run(解释器框架)
在System.Management.Automation.Translator.EnterTryCatchFinallyInstruction.Run(解释器框架)
在System.Management.Automation.Translator.EnterTryCatchFinallyInstruction.Run(解释器框架)
at系统。管理。自动化。解释器。解释器。运行(解释器框架)
at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
在System.Management.Automation.DlrScriptCommandProcessor.RunClause(操作'1子句,对象DollaRunBar,对象输入过程)
在System.Management.Automation.dlrscript命令处理器.Complete()中
在System.Management.Automation.CommandProcessorBase.DoComplete()中
位于System.Management.Automation.Internal.PipelineProcessor.DoCompleteCore(命令处理器或数据库命令请求流命令停止)
在System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(对象输入、哈希表错误结果、布尔枚举)
在System.Management.Automation.PipelineOps.InvokePieline(对象输入、布尔ignoreInput、CommandParameterInternal[][]pipeElements、CommandBaseAst[]pipeElementAsts、CommandRedirection[][]commandRedirections、FunctionContext funcContext)
at系统。管理。自动化。解释器。ActionCallInstruction`6。运行(解释器框架)
在System.Management.Automation.Translator.EnterTryCatchFinallyInstruction.Run(解释器框架)
在System.Management.Automation.Translator.EnterTryCatchFinallyInstruction.Run(解释器框架)
at系统。管理。自动化。解释器。解释器。运行(解释器框架)
at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
在System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseTovoke ClauseTovoke,Boolean createLocalScope,Dictionary`2 functionsToDefine,List`1 VariableToDefine,ErrorHandlingBehavior ErrorHandlingBehavior,Object dollarUnder,Object input,Object scriptThis,Pipe outputPipe,InvokingInfo InvokingInfo,Object[]args)
在System.Management.Automation.ScriptBlock.c__DisplayClassa.b__8()中
位于System.Management.Automation.Runspaces.RunspaceBase.RunActionIfNorRunningPipelineSwithThreadCheck(操作操作)
在System.Management.Automation.ScriptBlock.InvokeWithPipe(布尔值useLocalScope,Dictionary`2 functionsToDefine,List`1 VariableToDefine,ErrorHandlingBehavior ErrorHandlingBehavior,Object dollarUnder,Object input,Object scriptThis,Pipe outputPipe,InvocationInfo InvocationInfo,Object[]args)
位于System.Management.Automation.ScriptBlock.InvokeAsDelegateHelper(对象dollarUnder、对象dollarThis、对象[]args)
at lambda_方法(闭包、对象、事件参数)
在System.Windows.Forms.Control.OnClick(EventArgs e)中
在System.Windows.Forms.Button.OnClick(EventArgs e)中
在System.Windows.Forms.Button.OnMouseUp(MouseEventArgs-mevent)上
在System.Windows.Forms.Control.WmMouseUp(Message&m、MouseButtons按钮、Int32单击)
位于System.Windows.Forms.Control.WndProc(Message&m)
位于System.Windows.Forms.ButtonBase.WndProc(Message&m)
在System.Windows.Forms.Button.WndProc(Message&m)中
在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)中
在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)中
在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd、Int32 msg、IntPtr wparam、IntPtr lparam)中
(仅供参考,我已阅读)

我不知道在
if
语句中必须使用哪个条件

我还尝试了
[environment]::退出(0)
,但随后我的PowerShell环境关闭,我不希望这样

你们能帮我解决吗


亲切的问候。

我用了
返回
,一切正常

我尝试退出脚本应用程序时出现了相同的错误。 我解决了这个问题:

[System.Windows.Forms.Application]::Exit()

您好,什么是
$form
?为什么您认为您需要退出这里?$form是主要的gui界面。当用户存在时,我想停止脚本并关闭GUI表单。出于好奇,
$form.close()
是否足以关闭表单?只有GUI会关闭,但脚本仍在运行。返回时,脚本停止,GUI仍然打开。