【问题标题】:BMC Remedy AR Driver crashes powershellBMC Remedy AR Driver 崩溃 powershell
【发布时间】:2016-12-13 13:59:53
【问题描述】:

我的情况相当具体,所以我希望有人有一些见解可以帮助我。

代码

$id = Get-Credential "REMEDY\$($env:USERNAME)"
$userId = $id.UserName.split("\")[1].tolower()
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($id.password)
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) 

$cn = New-Object -comobject ADODB.Connection
$rs = New-Object -comobject ADODB.Recordset
$b = "Group5"
$c = "DSN=AR System ODBC Data Source;ARServer=remedyServer;ARServerPort=7130;UID=$userId;PWD=$password"
$cn.Open($c)
$q = "SELECT AuditTrail FROM HPD_HelpDesk WHERE AssignedToGroup='$b'"
$rs.Open($q, $cn)
while (!$rs.EOF) {
    $rs.Fields.item(0).value
    $rs.MoveNext()
}
$rs.close()
$cn.close()

司机:

Name: AR System ODBC Driver
Version: 7.06.04.30000
File: ARODBC7604_BUILD02.DLL

问题

在 Windows 7 32bit、powershell v4 下,一切都 100% 正常运行,没有错误。 在 Windows 10 64bit 下,它大约有 5% 的时间工作(强制 powershell x86 或者它根本看不到 ODBC 驱动程序,但这比问题更烦人)

错误

我什至很难得到错误,因为 Powershell 在发生这种情况时会立即完全关闭,但是从 CMD 运行它可以让我在它关闭之前看到输出。这是我得到的错误,同样的代码偶尔也会起作用。实际崩溃的行是 $rs.fields.item(0).value 行

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at IDispatchInvoke(IntPtr , Int32 , INVOKEKIND , DISPPARAMS& , Variant& , ExcepInfo& , UInt32& )
   at System.Management.Automation.ComInterop.UnsafeMethods.IDispatchInvoke(IntPtr dispatchPointer, Int32 memberDispId, INVOKEKIND flags, DISPPARAMS& dispParams, Variant& result, ExcepInfo& excepInfo, UInt32& argErr)
   at CallSite.Target(Closure , CallSite , ComObject )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
   at CallSite.Target(Closure , CallSite , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
   at System.Management.Automation.Interpreter.DynamicInstruction`2.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.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)
   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.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)
   at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
   at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
   at System.Management.Automation.Runspaces.PipelineThread.WorkerProc()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

【问题讨论】:

  • 不就是这个驱动不兼容windows 10吗?我无法想象这是一个powershell问题。 BMC 补救应用程序本身是否在系统上正常工作?
  • 是的,BMC 补救应用程序可以 100% 工作,就像 Microsoft Query 在 Excel 中使用此 DSN 一样。也许我还应该注意它只有像 AuditTrail 这样更大的字段,我可以拉 CaseID_ 直到奶牛回家
  • 查询在 64 位 Excel 或 32 位 Excel 中 100% 的工作时间?
  • 好点,它的 32 位 excel。该查询在 32 位下工作,除非我试图通过代码来完成,vb 也不起作用。它一定与那些特定的大文本字段有关,也许是不同的阅读方式?

标签: powershell odbc remedy


【解决方案1】:

能否请您更新驱动程序并检查它。这似乎更像是驱动程序问题而不是脚本。不过我还是建议您尝试其他一些 64 位系统,看看它是否有效。这样,至少您可以缩小问题的范围。

希望它能给你一个衬托。

【讨论】:

  • 不幸的是,我被这个驱动程序卡住了,它确实可以完美地作为 Remedy 应用程序运行,就像在 Excel 中使用 Microsoft Query 完成的相同查询一样,它只是不想玩得很好的 Powershell
  • 我能理解这种痛苦。但真的在这种情况下我很无奈。相同的脚本如何每次产生不同的输出。我没有测试 BMC 补救措施。那我得测试一下
【解决方案2】:

我不知道为什么会这样,而之前的方法失败了,但是这个可行

$id = Get-Credential "REMEDY\$($env:USERNAME)"
$userId = $id.UserName.split("\")[1].tolower()
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($id.password)
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)  
    write-host "Running Query"
    ##### Start the database connection and set up environment
    $DbString="DSN=AR System ODBC Data Source;UID=$userID;PWD=$password"
    $DBConnection=New-Object System.Data.Odbc.OdbcConnection
    $DBCommand=New-Object System.Data.Odbc.OdbcCommand
    $DBConnection.ConnectionString=$DbString
    $DBConnection.Open()
    $DBCommand.Connection=$DBConnection

    $SelectStatement="SELECT AuditTrail FROM HPD_HelpDesk WHERE AssignedToGroup='Group5'"
    $DBCommand.CommandText=$SelectStatement
    $DBResult=$DBCommand.ExecuteReader()
    $UserTable=New-Object system.data.datatable
    $UserTable.load($DBResult) 
    $UserTable
    sleep 3
}

我很想解释为什么会这样,但至少它是有效的:)

【讨论】:

    猜你喜欢
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多