Here is a shot code that works fine.
PS C:\Users\admin-s> $Disk_Counter
\Disque logique(F:)\Taille de file d’attente du disque actuelle
\Disque logique(F:)\Longueur moyenne de file d’attente du disque
\Disque logique(F:)\Longueur moyenne de file d’attente lecture disque
\Disque logique(F:)\Longueur moyenne de file d’attente écriture disque
PS C:\Users\admin-s> (Get-Counter -Counter $Disk_Counter) | Select-Object -Property CounterSamples, TimeStamp
CounterSamples Timestamp
-------------- ---------
{f:, f:, f:, f:} 30/09/2025 14:30:07
Now, I'd like to have the result of the 4 counter displayed in lines, with Timestamp repeated on each.
I tried to use -ExpandProperty that works for CounterSamples but I can't achieve to display TimeStamp
Thanks for your help
Tried this :
PS C:\Users\admin-s> (Get-Counter -Counter $Disk_Counter) | Select-Object -ExpandProperty CounterSamples -Property TimeStamp
Select-Object : La propriété ne peut pas être traitée, car la propriété « Timestamp » existe déjà.
Au caractère Ligne:1 : 41
+ ... _Counter) | Select-Object -ExpandProperty CounterSamples -Property Ti ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation : (Microsoft.Power...ounterSampleSet:PSObject) [Select-Object], PSArgumentException
+ FullyQualifiedErrorId : AlreadyExistingUserSpecifiedPropertyExpand,Microsoft.PowerShell.Commands.SelectObjectCommand
Expecting :
Path InstanceName CookedValue TimeStamp
The error is telling you that the cmdlet is failing to add a TimeStamp Property to the objects in .CounterSamples, this is due to this property already existing on them, just that you don't see them due to the object's default formatting. This error is also hinted in the documentation, see the warning box in -ExpandProperty.
The default formatting is set via PSStandardMembers to show the following default properties:
$counter = Get-Counter -Counter $Disk_Counter
$counter.CounterSamples[0].PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames
# Path
# InstanceName
# CookedValue
If you want to see the default properties: Path, InstanceName and CookedValue and add Timestamp to it, you could do:
Get-Counter -Counter $Disk_Counter |
ForEach-Object CounterSamples |
Select-Object Path, InstanceName, CookedValue, Timestamp