[WHQL自动化]如何在powershell中捕获ProjectMangerException类 [英] [WHQL automation] How to trap ProjectMangerException Class in powershell

查看:86
本文介绍了[WHQL自动化]如何在powershell中捕获ProjectMangerException类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尝试控制器无效然后它应该去异常处理,但我的测试总是失败,以下是我的代码,可以帮助吗?

Hi, I want to try if Controller is invalid then it should go to exception handling ,but my test always failed ,Following is my code ,Could any one help ?

$ ObjectModel = [Reflection.Assembly] :: LoadFrom($ env:WTTSTDIO +" microsoft.windows.Kits.Hardware.objectmodel.dll")

$ ObjectModel = [Reflection.Assembly] :: LoadFrom($ env:WTTSTDIO +" microsoft.windows.Kits.Hardware.objectmodel.dbconnection.dll")

$ObjectModel = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "microsoft.windows.Kits.Hardware.objectmodel.dll")
$ObjectModel = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "microsoft.windows.Kits.Hardware.objectmodel.dbconnection.dll")

$ ControllerName = " invalid"

$ControllerName = "invalid"

$ Manager = new-object -typename Microsoft.Windows.Kits.Hardware.ObjectModel.DBConnection.DatabaseProjectManager -Args $ ControllerName,DTMJobs

$Manager = new-object -typename Microsoft.Windows.Kits.Hardware.ObjectModel.DBConnection.DatabaseProjectManager -Args $ControllerName, DTMJobs

=============================================== =====

====================================================

场景1:

$ ProjectManagerException = new-object -typename Microsoft.Windows.Kits.Hardware.ObjectModel.ProjectManagerException 

陷阱[$ ProjectManagerException] {

写主持人Mike Donot希望你使用它 

退出

}

$ProjectManagerException = new-object -typename Microsoft.Windows.Kits.Hardware.ObjectModel.ProjectManagerException 
Trap [$ ProjectManagerException] {
Write-Host Mike donot want you use it 
exit
}

提示:

无法找到类型[$ ProjectManagerException]:确保已加载包含此类型的程序集。

在C:\ Users \Administrator \Documents\GitHub \ whql_autoit \\\
etkvm.ps1:55 char:34

+  &NBSP;陷阱[$ ProjectManagerException]<<<<   {

  &NBSP; + CategoryInfo  &NBSP; &NBSP; &NBSP;  :InvalidOperation:($ ProjectManagerException:String)[],RuntimeException

  &NBSP; + FullyQualifiedErrorId:TypeNotFound

Unable to find type [ $ProjectManagerException]: make sure that the assembly containing this type is loaded.
At C:\Users\Administrator\Documents\GitHub\whql_autoit\netkvm.ps1:55 char:34
+     Trap [ $ProjectManagerException] <<<<  {
    + CategoryInfo          : InvalidOperation: ( $ProjectManagerException:String) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

============= =================================

==============================================

场景2:

陷阱[Microsoft.Windows.Kits.Hardware.ObjectModel.ProjectManagerException] {

写入主机Mike donot希望你使用它 

退出

}

Trap [ Microsoft.Windows.Kits.Hardware.ObjectModel.ProjectManagerException] {
Write-Host Mike donot want you use it 
exit
}

New-Object:异常调用" .ctor"用"2"表示"2"。参数:"无法连接到数据库"
$
在C:\ Users \Administrator \Documents\GitHub \whql_autoit \ Library_HCK_MachinePoolAPI.ps1:36 char:15

+  &NBSP; new-object<<<<   -typename Microsoft.Windows.Kits.Hardware.ObjectModel.DBConnection.DatabaseProjectManager -Args

$ ControllerName,DTMJobs

  &NBSP; + CategoryInfo  &NBSP; &NBSP; &NBSP;  :InvalidOperation:(:) [New-Object],MethodInvocationException

  &NBSP; + FullyQualifiedErrorId:ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

New-Object : Exception calling ".ctor" with "2" argument(s): "Failed to connect to the database"
At C:\Users\Administrator\Documents\GitHub\whql_autoit\Library_HCK_MachinePoolAPI.ps1:36 char:15
+     new-object <<<<  -typename Microsoft.Windows.Kits.Hardware.ObjectModel.DBConnection.DatabaseProjectManager -Args
$ControllerName, DTMJobs
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

=========================== =============================

========================================================

Trap [ProjectManagerException] {

写主持人Mike Donot希望你使用它 

退出$
}

Trap [ProjectManagerException] {
Write-Host Mike donot want you use it 
exit
}

场景3:

无法找到类型[ProjectManagerException]:确保已加载包含此类型的程序集。

在C:\ Users \Administrator \Documents\GitHub\whql_autoit \\ \\ netkvm.ps1:55 char:32

+  &NBSP;陷阱[ProjectManagerException]<<<<   {

  &NBSP; + CategoryInfo  &NBSP; &NBSP; &NBSP;  :InvalidOperation:(ProjectManagerException:String)[],RuntimeException

  &NBSP; + FullyQualifiedErrorId:TypeNotFound

Unable to find type [ProjectManagerException]: make sure that the assembly containing this type is loaded.
At C:\Users\Administrator\Documents\GitHub\whql_autoit\netkvm.ps1:55 char:32
+     Trap [ProjectManagerException] <<<<  {
    + CategoryInfo          : InvalidOperation: (ProjectManagerException:String) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

场景4:

陷阱[例外] {

写-Host Mike donot希望你使用它 

退出

Trap [Exception] {
Write-Host Mike donot want you use it 
exit

}

工作正常,它提示"Mike Donot希望你使用它"

works fine ,it prompts " Mike donot want you use it "

我如何使用  PowerShell中的ProjectMangerException类?

How Could I use  ProjectMangerException Class  in powershell ?

谢谢,

最诚挚的问候,迈克

推荐答案

我建议,不要硬编码控制器名称,而是这样:

I would suggest, instead of hardcoding the controllername, get it like this:


controllerName = [System.Net.DNS] :: GetHostName()
controllerName=[System.Net.DNS]::GetHostName()

然后,

尝试

{


Manager = new-object -typename Microsoft.Windows.Kits。 Hardware.ObjectMo del.DBConnection.DatabaseProjectManager -Args
Manager = new-object -typename Microsoft.Windows.Kits.Hardware.ObjectModel.DBConnection.DatabaseProjectManager -Args


这篇关于[WHQL自动化]如何在powershell中捕获ProjectMangerException类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆