PowerCLI"New-VM"在Hybrid Worker上失败,但同时充当计划任务和交互Powershell [英] PowerCLI "New-VM" Fails on Hybrid Worker but works as both scheduled task and interactivly powershell

查看:323
本文介绍了PowerCLI"New-VM"在Hybrid Worker上失败,但同时充当计划任务和交互Powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经在脚本服务器上安装了Azure Hybrid工作者.

我可以将本地系统/本地服务或网络服务作为计划任务或以交互方式启动脚本.

但是,如果通过测试窗格运行该测试失败,并且由于错误消息而导致的通知不正确,则该失败会在Azure Runbook上运行

New-VM:2018/6/27下午4:05:30 New-VM找不到项目C:\ ProgramData.

在线:56个字符:1

+ New-VM -Name $ VMname -template $ myTemplate -location $ env -ResourcePo ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo         :未指定:(:) [New-VM],VimException

+ FullyQualifiedErrorId:Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

将其配对到我的脚本中,以使其变得简单

Param(
[String] $ VMNamesuffix ='MyTestServerLocal',
[string] $ Env ="Test01",
[String] $ VCServiceAccount ="Domain \ svc_UserAccount",
[String] $ VCServicePassword =" SomePassword"
)
##变量##
$ VMname =($ Env +-" + $ VMNameSuffix).ToUpper()
$ sourcevc =" vcenter01.domain.test"
$ TargetDataStore ="TFC_XIO _" + $ env
$ sourceDS ='TFC_XIO_UTILITY'
$ ResourcePool ='GoldRP'
#要加载的模块列表
$ moduleList = @(
    " VMware.VimAutomation.Core",
    " VMware.VimAutomation.Vds",
    " VMware.VimAutomation.Cloud",
    " VMware.VimAutomation.PCloud",
    "VMware.VimAutomation.Cis.Core",
    "VMware.VimAutomation.Storage",
    " VMware.VimAutomation.Horizo​​nView",
    " VMware.VimAutomation.HA",
    "VMware.VimAutomation.vROps",
    " VMware.VumAutomation",
    " VMware.DeployAutomation",
    " VMware.ImageBuilder",
    "VMware.VimAutomation.License"
    )
#个加载模块
function LoadModules(){

$ loaded =获取模块-名称$ moduleList -ErrorAction忽略| %{$ _.Name}
   $ registered = Get-Module -Name $ moduleList -ListAvailable -ErrorAction忽略| %{$ _.Name}
   $ notLoaded = $ registered | ? {$ loaded -notcontains $ _}
 
   foreach($ registered中的$ module){
     if($ loaded -notcontains $ module){
        
  导入模块$ module

      }
   }
}
#Run LoadModules函数
LoadModules


$ VCSecurePassword = Convertto-SecureString -String $ VCServicePassword -AsPlainText -force
$ VCCreds =新对象System.Management.Automation.PSCredential $ VCServiceAccount,$ VCSecurePassword
连接VIServer-服务器$ sourcevc-凭据$ VCCreds

$ SourceDataStoreOB = Get-Datastore $ SourceDataStore
$ TargetDataStoreOB =获取数据存储区$ TargetDataStore

$ myTemplate = Get-Template -Name" WinTemplate" -位置模板
新VM-名称$ VMname-模板$ myTemplate-位置$ env -ResourcePool $ ResourcePool -Datastore $ TargetDataStoreOB -Verbose

解决方案

由于New-VM cmdlet本身已出现异常,因此最好联系VMware人们了解此异常的含义.不幸的是,它看起来像是一种包罗万象的异常.

我还建议尝试捕获调试流,以查看是否在其中捕获了任何其他信息.由于Azure自动化不会记录调试流,因此您需要重定向流.指示 这里.

快速查看Bing似乎可以出于多种原因引发此异常,但是它们似乎都具有尝试访问缺少的或已经存在的资源的通用线程.

尝试进行的另一个故障排除步骤是捕获 流程监控器日志.由于该异常为您提供了它正在尝试查找的特定资源,因此procmon日志可能会帮助您提供一些线索,以了解它正试图对该资源执行的操作以及它是否确实丢失了 或存在访问问题或诸如此类的问题,其中吞没了真正的异常并将该通用异常替换为原来的位置.

-杰夫.


So I have installed a Azure Hybrid worker on my script server.

I can launch a script with Local System / Local Service or Network Service as a scheduled task or interactively.

But running it through Test Pane in fails on the Azure Runbook if fails with a rather non-informed error

New-VM : 6/27/2018 4:05:30 PM New-VM Could not find item C:\ProgramData.

At line:56 char:1

+ New-VM -Name $VMname -template $myTemplate -location $env -ResourcePo ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [New-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

Paired it down my script , to make it simple

Param (
[String]$VMNamesuffix = 'MyTestServerLocal',
[string]$Env = "Test01",
[String]$VCServiceAccount ="Domain\svc_UserAccount",
[String]$VCServicePassword = "SomePassword"
)
## Varaibles ##
$VMname = ($Env+"-"+$VMNameSuffix).ToUpper()
$sourcevc = "vcenter01.domain.test"
$TargetDataStore = "TFC_XIO_"+$env
$sourceDS = 'TFC_XIO_UTILITY'
$ResourcePool = 'GoldRP'
# List of modules to be loaded
$moduleList = @(
    "VMware.VimAutomation.Core",
    "VMware.VimAutomation.Vds",
    "VMware.VimAutomation.Cloud",
    "VMware.VimAutomation.PCloud",
    "VMware.VimAutomation.Cis.Core",
    "VMware.VimAutomation.Storage",
    "VMware.VimAutomation.HorizonView",
    "VMware.VimAutomation.HA",
    "VMware.VimAutomation.vROps",
    "VMware.VumAutomation",
    "VMware.DeployAutomation",
    "VMware.ImageBuilder",
    "VMware.VimAutomation.License"
    )
# Load modules
function LoadModules(){

   $loaded = Get-Module -Name $moduleList -ErrorAction Ignore | % {$_.Name}
   $registered = Get-Module -Name $moduleList -ListAvailable -ErrorAction Ignore | % {$_.Name}
   $notLoaded = $registered | ? {$loaded -notcontains $_}
 
   foreach ($module in $registered) {
      if ($loaded -notcontains $module) {
        
   Import-Module $module

      }
   }
}
#Run LoadModules function
LoadModules


$VCSecurePassword = Convertto-SecureString -String $VCServicePassword -AsPlainText -force
$VCCreds = New-object System.Management.Automation.PSCredential $VCServiceAccount ,$VCSecurePassword
Connect-VIServer -Server $sourcevc -Credential $VCCreds

$SourceDataStoreOB = Get-Datastore $SourceDataStore
$TargetDataStoreOB= Get-Datastore $TargetDataStore

$myTemplate = Get-Template -Name "WinTemplate" -Location Templates
New-VM -Name $VMname -template $myTemplate -location $env -ResourcePool $ResourcePool -Datastore $TargetDataStoreOB -Verbose

解决方案

Since the exception is coming out of the New-VM cmdlet itself it might be better to reach out to the VMware folks to find out what this exception means.  Unfortunately it looks like some kind of a catch-all exception.

I would also recommend to try capturing debug streams to see if any additional information is captured there.  Since Azure Automation doesn't log debug streams you'll need to redirect the streams.  Instructions here.

Doing some quick Bing sleuthing it appears that this exception can be thrown for a number of varying reasons but they all seem to have a common thread of attempting to access a resource that is either missing, or already exists.

Another troubleshooting step to try would be to capture a Process Monitor log.  Since the exception is giving you a specific resource that it is trying to find, the procmon log might help to give you some clues as to what exactly it is trying to do with that resource and whether or not it really is missing or if there was an access issue or something like that where the real exception has been swallowed and this generic exception thrown in its place.

-Jeff.


这篇关于PowerCLI"New-VM"在Hybrid Worker上失败,但同时充当计划任务和交互Powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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