我正在寻找一种 powershell 方法来断开虚拟机与 OMS 工作区的连接。
我编写了一个 powershell 脚本来将虚拟机移动到其他订阅。所以我必须将此虚拟机从“源工作区”重新连接到“目标工作区”。
仅删除 OMS 扩展后,虚拟机在 Azure 门户“Log Analytics 工作区 > 工作区数据源 > 虚拟机”中显示为“未连接”。
这个 cmdlet 应该可以解决问题( the doc is not really clear ),但我总是收到相同的消息
remove-AzureRmOperationalInsightsDataSource -Workspace $OmsWkspceITS -Name CentosMove
Confirm
Are you sure you want to remove data source 'CentosMove' in workspace 'itsoms'?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Yes"): yes
WARNING: DataSource 'CentosMove' does not exist in workspace 'itsoms'.
(CentosMove 是我的虚拟机名称)。
我们的 ITSOMS 工作区已使用多年,拥有数百个虚拟机、许多解决方案、NSG 日志流分析......
$OmsWkspceITS
Name : itsoms
ResourceGroupName : rg_its_exploit
ResourceId : /subscriptions/blablabla/resourcegroups/blabla/providers/microsoft.operationalinsights/workspaces/itsoms
Location : westeurope
Tags :
Sku : standalone
CustomerId : xx
PortalUrl : https://weu.mms.microsoft.com/Accou...
ProvisioningState : Succeeded
我可以使用此 cmdlet 获得的唯一数据源是像这样的数据源
Get-AzureRmOperationalInsightsDataSource -WorkspaceName $OmsWkspceITS.Name -ResourceGroupName $OmsWkspceITS.ResourceGroupName -Name DataSource_LinuxSyslog_syslog
Name : DataSource_LinuxSyslog_syslog
ResourceGroupName : rg_its_exploit
WorkspaceName : itsoms
ResourceId : /subscriptions/xx/resourceGroups/rg_its_exploit/providers/Microsoft.OperationalInsights/workspaces/itsoms/datasources/DataSource_LinuxSyslog_syslog
Kind : LinuxSyslog
Properties : {"syslogName":"syslog".....}
我认为我可能没有看到正确的 cmdlet ...
感谢您的帮助:)
最佳答案
要满足您的要求,请使用 cmdlet Remove-AzureRmVMExtension 和 Set-AzureRmVMExtension。
为了便于说明,请检查以下命令。
要断开 Linux VM 代理:
Remove-AzureRmVMExtension -ResourceGroupName RESOURCEGROUPNAME -VMName VMNAME -Name ‘OmsAgentForLinux’
要断开 Windows VM 代理:
Remove-AzureRmVMExtension -ResourceGroupName RESOURCEGROUPNAME -VMName VMNAME -Name ‘MicrosoftMonitoringAgent’
要将 Linux VM 代理连接到 Log Analytics 工作区:
$WorkspaceID = "xxxxxxxxxxxxxxxxxxxxxxxxx"
$WorkspaceKey = "xxxxxxxxxxxxxxxxxxxxxxxx"
Set-AzureRmVMExtension -ResourceGroupName RESOURCEGROUPNAME -VMName VMNAME -Name ‘OmsAgentForLinux’ -Publisher ‘Microsoft.EnterpriseCloud.Monitoring’ -ExtensionType ‘OmsAgentForLinux’ -TypeHandlerVersion ‘1.0’ -Location 'LOCATION' -SettingString "{‘workspaceId’: ‘$WorkspaceID’}" -ProtectedSettingString "{‘workspaceKey’: ‘$WorkspaceKey’}"
要将 Windows VM 代理连接到 Log Analytics 工作区:
$WorkspaceID = "xxxxxxxxxxxxxxxxxxxxxxxxx"
$WorkspaceKey = "xxxxxxxxxxxxxxxxxxxxxxxx"
Set-AzureRmVMExtension -ResourceGroupName RESOURCEGROUPNAME -VMName VMNAME -Name ‘MicrosoftMonitoringAgent’ -Publisher ‘Microsoft.EnterpriseCloud.Monitoring’ -ExtensionType ‘MicrosoftMonitoringAgent’ -TypeHandlerVersion ‘1.0’ -Location 'LOCATION' -SettingString "{‘workspaceId’: ‘$WorkspaceID’}" -ProtectedSettingString "{‘workspaceKey’: ‘$WorkspaceKey’}"
希望这有帮助!干杯!! :)
关于azure - 断开 Azure VM 与 loganalytics 工作区的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54687709/