获取 Azure 混合工作组的上次查看时间

Get the last seen time for Azure Hybrid worker group

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

这是 Get-AzureRmAutomationHybridWorkerGroupcommandlet 的一个未决问题,请参阅 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
资源名称
资源类型
资源组名称 订阅 ID

尽管数据作为调试 ($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/

最后我通过从 Az.Automation 模块导入最新版本 0.6.1 使其工作。 对于带有前缀 AzureRM 和版本 6.13.1 的 "old" commandlet 也是如此: https://www.powershellgallery.com/packages/AzureRM/6.13.1

缺失的 属性 问题已在 9 月修复 (https://github.com/Azure/azure-powershell/commit/e098199011c3ad09ef94a0b70f6de76f61bddd12#diff-f3a5751aabbc428aaa014a0c847c2e61)

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