Forum Discussion
Azure PowerShell find LastOwnershipUpdateTime on disk
- Dec 17, 2024
# Ensure you're connected to Azure
Connect-AzAccount# Get the disk details with extended properties
$disk = Get-AzDisk -ResourceGroupName "YourResourceGroupName" -DiskName "YourDiskName"# Check the LastOwnershipUpdateTime property
$disk.LastOwnershipUpdateTimeIf the property isn't directly accessible, you can try using the underlying REST API call:
# Get the disk resource
$disk = Get-AzDisk -ResourceGroupName "YourResourceGroupName" -DiskName "YourDiskName"# Use the full resource ID to fetch detailed properties
$detailedDisk = Invoke-AzRestMethod -Path "$($disk.Id)?api-version=2023-10-02" -Method GET# Parse the response to extract LastOwnershipUpdateTime
$detailedProperties = $detailedDisk.Content | ConvertFrom-Json
$lastOwnershipUpdateTime = $detailedProperties.LastOwnershipUpdateTimeIf you want to get this for multiple disks:
# List all disks in a resource group
$disks = Get-AzDisk -ResourceGroupName "YourResourceGroupName"# Filter and display LastOwnershipUpdateTime
$disks | ForEach-Object {
[PSCustomObject]@{
DiskName = $_.Name
LastOwnershipUpdateTime = $_.LastOwnershipUpdateTime
}
}A few important notes:
- Ensure you're using the latest Az.Compute module (version 9.0.0 or higher)
- Make sure you're authenticated with Connect-AzAccount
- Replace "YourResourceGroupName" and "YourDiskName" with your actual resource group and disk names
- The property might not be available on older disks or in all Azure regions
# Ensure you're connected to Azure
Connect-AzAccount
# Get the disk details with extended properties
$disk = Get-AzDisk -ResourceGroupName "YourResourceGroupName" -DiskName "YourDiskName"
# Check the LastOwnershipUpdateTime property
$disk.LastOwnershipUpdateTime
If the property isn't directly accessible, you can try using the underlying REST API call:
# Get the disk resource
$disk = Get-AzDisk -ResourceGroupName "YourResourceGroupName" -DiskName "YourDiskName"
# Use the full resource ID to fetch detailed properties
$detailedDisk = Invoke-AzRestMethod -Path "$($disk.Id)?api-version=2023-10-02" -Method GET
# Parse the response to extract LastOwnershipUpdateTime
$detailedProperties = $detailedDisk.Content | ConvertFrom-Json
$lastOwnershipUpdateTime = $detailedProperties.LastOwnershipUpdateTime
If you want to get this for multiple disks:
# List all disks in a resource group
$disks = Get-AzDisk -ResourceGroupName "YourResourceGroupName"
# Filter and display LastOwnershipUpdateTime
$disks | ForEach-Object {
[PSCustomObject]@{
DiskName = $_.Name
LastOwnershipUpdateTime = $_.LastOwnershipUpdateTime
}
}
A few important notes:
- Ensure you're using the latest Az.Compute module (version 9.0.0 or higher)
- Make sure you're authenticated with Connect-AzAccount
- Replace "YourResourceGroupName" and "YourDiskName" with your actual resource group and disk names
- The property might not be available on older disks or in all Azure regions