raptor85
raptor85

Reputation: 125

TimeCreated property not returning unique value Get-AzureRmDisk

I am trying to extract date creation of os-disk in azure portal. I am able to generate os-disk lists from Get-AzureRmDisk cmdlet.

however, when i try to extract timecreation date with -unique parameters. the results shows duplicate values

 $disks = Get-AzureRmDisk -ResourceGroupName "testGroup"
 $osdisk = $disks.Name -match '-osdisk'

Result :

enter image description here

$datess = $osdisk.TimeCreated | Select-Object -Unique
 $datess

Result :

enter image description here

As we can see there is an additional duplicated date which is being displayed. Any suggestions on how i can get date of the particular Azure os disk

Upvotes: 0

Views: 227

Answers (1)

juvchan
juvchan

Reputation: 6245

You could format the TimeCreated value into the Date Time format which is easier for comparison and duplicate filtering.

The result of the code below is either True or False:

$osdisk = $disks.Name -match '-osdisk'

Please see the suggested changes:

$osdisk = $disks | where {$_.Name -match '_osdisk'}
$datess = $osdisk.TimeCreated | %{Get-Date $_ -f 'yyyy-MM-dd HH:mm:ss'} | Select -Unique

The changes have been tested working.

Upvotes: 1

Related Questions