获取Azure Hybrid工作组的最后一次查看时间

时间:2018-11-16 08:38:35

标签: azure powershell azure-automation

我正在尝试使用PowerShell检索混合工组的最后一次看到的时间值。但是,我找不到“ Get-AzureRMAutomationHybridWorkerGroup”的任何参数或此Cmdlet的成员都可以检索该值。我看到我只能检索注册时间。有什么建议吗?

2 个答案:

答案 0 :(得分:1)

最后,我从Az.Automation模块中导入了最新的0.6.1版,从而使它正常工作。 具有前缀AzureRM和版本6.13.1的“旧”命令行开关也是如此: https://www.powershellgallery.com/packages/AzureRM/6.13.1

失物招领已经在9月(https://github.com/Azure/azure-powershell/commit/e098199011c3ad09ef94a0b70f6de76f61bddd12#diff-f3a5751aabbc428aaa014a0c847c2e61)中得到修复

enter image description here

PS /home/Falco> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.6.1      Az.Automation                       {Export-AzAutomationDscConfiguration, Export-AzAutomationDscNodeReportContent, Export-AzAutomationRunbook, Get-AzAutomationAccount...}
Script     0.6.1      Az.Profile                          {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount...}

版本0.5.0之前已安装,并且存在缺少日期的问题。

这将为您提供所需的结果。

PS /home/Falco> (Get-AzAutomationHybridWorkerGroup -ResourceGroupName RG1 -AutomationAccountName Automationtest).RunbookWorker | fl


IpAddress        : 192.168.1.7,172.17.192.1,172.18.201.17
Name             : Server
RegistrationTime : 11/18/18 11:55:52 PM +00:00
LastSeenDateTime : 11/22/18 1:25:23 AM +00:00

答案 1 :(得分:0)

这是Get-AzureRmAutomationHybridWorkerGroup commandlet的未解决问题,请参阅 https://github.com/Azure/azure-powershell/issues/5959

直到修复,您需要采用通用方式并进行一些API调用:

第一次检查 https://resources.azure.com并搜索您的资源和缺少的属性。 那么您就可以使用powershell像这样检索它们了:

Get-AzureRmResource -ResourceGroupName RG1 -ResourceType Microsoft.Automation/automationAccounts/hybridRunbookWorkerGroups -ResourceName "AutomationTest" -ApiVersion 2015-10-31

即使通用Cmdlet仅显示以下值,也不会检索lastSeendatetime值:

名称
ResourceId
ResourceName
ResourceType
ResourceGroupName SubscriptionId

尽管数据是按照调试($DebugPreference="Continue")输出显示的:

Body:
{
  "value": [
    {
      "id":
"/subscriptions/12345xyz/resourceGroups/RG1/providers/Microsoft.Automation/automationAccounts/automationtest/hybridRunbookWorkerGr
oups/TestHy",
      "name": "TestHy",
      "hybridRunbookWorkers": [
        {
          "name": "Server1",
          "ip": "4.4.4.4",
          "registrationTime": "2018-11-19T00:55:52.0407467+01:00",
          "lastSeenDateTime": "2018-11-19T17:16:48.497+01:00",
          "azureResourceId": ""
        }
      ],
      "credential": null,
      "groupType": "User"
    }
  ]
}

作为解决方法,您可以捕获调试输出

(Get-AzureRMAutomationHybridWorkerGroup -ResourceGroupName RG1 -AutomationAccountName test ) 5>&1 | Set-Variable out  并从该字符串中提取lastSeenDateTime,例如与$out | findstr "lastseen"

检查https://docs.microsoft.com/en-us/rest/api/automation/hybridrunbookworkergroup/get 以正确的方式通过REST调用来获得所需的属性,但是必须再次进行身份验证,但是有一些提示可以用Google搜索,例如https://blog.tekspace.io/access-azure-rest-api-using-powershell/

相关问题