Get Azure VM Boot Diagnostics and filter some string to print out to the console using powershell.

Swathi Reddy 186 Reputation points
2020-12-21T10:10:58.207+00:00

Get Azure VM Boot Diagnostics and filter some string to print out to the console using powershell.

I have used the below script using parameters :

param(
[Parameter(Mandatory=$true)]
[string]$vm,
[Parameter(Mandatory=$true)]
[string]$resourcegroup,
[Parameter(Mandatory=$true)]
[string]$storageaccountname,
[Parameter(Mandatory=$true)]
[string]$localpath
)

$vm = Get-AzureRmVM -ResourceGroupName $resourcegroup -Name $vm
Set-AzureRmVMBootDiagnostics -VM $VM -Enable -ResourceGroupName $resourcegroup -StorageAccountName $storageaccountname
Set-AzureRmVMBootDiagnostics -VM $VM -Enable -ResourceGroupName $resourcegroup -StorageAccountName $storageaccountname |Update-AzurermVM

Get-AzureRmVMBootDiagnosticsData -ResourceGroupName $resourcegroup -Name $vm -Windows -LocalPath $localpath

Output is getting error :

cmdlet Task3.1.ps1 at command pipeline position 1
Supply values for the following parameters:
vm: azbootvm
resourcegroup: AzRg
storageaccountname: mystacc
localpath: c:\folder
Set-AzureRmVMBootDiagnostics : Cannot bind parameter 'VM'. Cannot convert the
"Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine" value of type "System.String" to type
"Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine".
At

  • Set-AzureRmVMBootDiagnostics -VM $VM -Enable -ResourceGroupName $reso ...
  • ~~~
  • CategoryInfo : InvalidArgument: (:) [Set-AzureRmVMBootDiagnostics], ParameterBindingException
  • FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.Commands.Compute.SetAzureVMBootDiagnostic
    sCommand

Set-AzureRmVMBootDiagnostics : Cannot bind parameter 'VM'. Cannot convert the
"Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine" value of type "System.String" to type
"Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine".
At

  • Set-AzureRmVMBootDiagnostics -VM $VM -Enable -ResourceGroupName $reso ...
  • ~~~
  • CategoryInfo : InvalidArgument: (:) [Set-AzureRmVMBootDiagnostics], ParameterBindingException
  • FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.Commands.Compute.SetAzureVMBootDiagnostic
    sCommand

Get-AzureRmVMBootDiagnosticsData : The Resource
'Microsoft.Compute/virtualMachines/Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine' under resource group
'AzRg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
ErrorCode: ResourceNotFound
ErrorMessage: The Resource
'Microsoft.Compute/virtualMachines/Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine' under resource group
'AzRg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
ErrorTarget:
StatusCode: 404
ReasonPhrase: Not Found
OperationID : 02ec93c5-8e59-4cff-a551-0a20cebb80dc
At

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Andreas Baumgarten 104K Reputation points MVP
    2020-12-21T11:15:51.89+00:00

    First of all I would recommend to use Az instead of AzureRM because AzureRM is outdated.
    https://learn.microsoft.com/de-de/powershell/azure/migrate-from-azurerm-to-az?view=azps-5.2.0

    I would start with getting the Azure ResourceGroup object:

    ...  
    $resourcegroup = Get-AzureRmResourceGroup -Name $resourcegroup  
    $vm = Get-AzureRmVM -ResourceGroupName $resourcegroup -Name $vm  
    ...  
    

    It could be helpful for troubleshooting to output both variables just to see if objects are found (later you can delete the output again):

    $resourcegroup = Get-AzureRmResourceGroup -Name $resourcegroup  
    $resourcegroup  
    $vm = Get-AzureRmVM -ResourceGroupName $resourcegroup -Name $vm  
    $vm  
      
    

    Check the output of $vm which type it is with $vm.GetType() . The type needs to be Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten