简体   繁体   English

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

[英]System.Management.Automation.ExitException: System error in Powershell Studio

I made a script in Powershell: when I import the CSV file I want to check if the users already exists.我在 Powershell 中创建了一个脚本:当我导入 CSV 文件时,我想检查用户是否已经存在。 This is the script:这是脚本:

$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
}

When the user already exists I get the following error:当用户已经存在时,我收到以下错误:

************** 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)

(FYI I already have read this SO post ) (仅供参考,我已经阅读了这篇 SO 帖子

I don't know which condition I have to use in the if statement.我不知道我必须在if语句中使用哪个条件。

I also tried with [environment]::exit(0) but then my PowerShell environment closes and I don't want that.我也尝试过[environment]::exit(0)但后来我的 PowerShell 环境关闭了,我不想要那样。

Can you guys help me with a solution?你们能帮我解决一下吗?

Kind regards.亲切的问候。

我使用了return ,一切正常!

I had the same error when I try to exit the script app.当我尝试退出脚本应用程序时,我遇到了同样的错误。 I solved it with this:我用这个解决了它:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Management.Automation中没有PowerShell? - No PowerShell in System.Management.Automation? Powershell运行空间实例化错误:未找到System.Management.Automation - Powershell runspace instantiate error: System.Management.Automation not found Powershell 脚本在 SetAccessRule 上抛出 System.Management.Automation.PSMethod 错误 - Powershell script throwing System.Management.Automation.PSMethod error on SetAccessRule 在Powershell中找不到类型[System.Management.Automation.IValidateSetValuesGenerator]错误 - Unable to find type [System.Management.Automation.IValidateSetValuesGenerator] error in Powershell MVC System.Management.Automation Powershell执行中的访问被拒绝错误 - Access Denied error in MVC System.Management.Automation powershell execution 获取 PowerShell 脚本中的错误位置 (System.Management.Automation) - Get Location of Error in PowerShell script (System.Management.Automation) System.Management.Automation.Powershell RunAs管理员 - System.Management.Automation.Powershell RunAs Admin 在PowerShell上运行良好的脚本使用System.Management.Automation.PowerShell返回错误 - Script that runs fine on PowerShell returns error using System.Management.Automation.PowerShell Powershell - 无法将“System.Management.Automation.PSCustomObject”类型的值转换为“System.Management.Automation.PSCustomObject”类型 - Powershell - Cannot convert value of type "System.Management.Automation.PSCustomObject" to type "System.Management.Automation.PSCustomObject" 如何向 powershell 脚本 (System.Management.Automation.Powershell) 提供参数? - How to supply parameters to powershell script (System.Management.Automation.Powershell)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM