Hi,
Finally
[String]$Str_ClassName="ProfileSize"
[Array]$Arr_Property=@("Name","Count","Total","DateCreate","TreatmentDuration")
$WMI_Class = ""
$WMI_Class = New-Object System.Management.ManagementClass("Root\cimv2", $null, $null)
$WMI_Class.name = $Str_ClassName
#Test class existence and remove it if existing
$class = Get-WmiObject -Class $Str_ClassName -List -Namespace 'root\cimv2';
If ($class -ine $null) {Remove-WmiObject -Class $Str_ClassName}
#Création de la classe
$WMI_Class["__CLASS"] = $Str_ClassName
#Get userprofiles
[array]$Arr_users = Get-ChildItem -Path "$envsystemdrive\Users"
#Instance creation
$Arr_users | ForEach-Object {
#Start the clock
$stopwatch=[system.diagnostics.stopwatch]::StartNew()
$colItems = (Get-ChildItem $env:systemdrive\Users\$($_.Name) -recurse -Force -ErrorAction SilentlyContinue | Measure-Object -property length -sum)
$DirectorySizeMB = [math]::Round($colItems.sum / 1MB,1)
Write-host "$($_.Name): $DirectorySizeMB Mo"
#Stop the clock
$stopwatch.stop()
$arglist = @{
Name = $($_.Name) #Profile name
Count = $($colItems.Count).ToString() #How many files in the profile?
#Total = $($colItems.sum).ToString()
Total = $DirectorySizeMB.ToString() #Total size for that profil?
DateCreate=$(get-date).tostring() #When that profil was evaluate?
TreatmentDuration=$([math]::Round($($stopwatch.Elapsed).totalseconds,1)).tostring() #How much time to calculate that profile in second.
}
$WMI_Class.Properties.Add("Name", [System.Management.CimType]::String, $false)
$WMI_Class.Properties["Name"].Qualifiers.Add("key", $true)
$WMI_Class.Properties.Add("Total", [System.Management.CimType]::String, $false)
$WMI_Class.Properties["Total"].Qualifiers.Add("key", $true)
$WMI_Class.Properties.Add("Count", [System.Management.CimType]::String, $false)
$WMI_Class.Properties["Count"].Qualifiers.Add("key", $true)
$WMI_Class.Properties.Add("DateCreate", [System.Management.CimType]::String, $false)
$WMI_Class.Properties["DateCreate"].Qualifiers.Add("key", $true)
$WMI_Class.Properties.Add("TreatmentDuration", [System.Management.CimType]::String, $false)
$WMI_Class.Properties["TreatmentDuration"].Qualifiers.Add("key", $true)
$WMI_Class.Put()
Set-WmiInstance -Class $Str_ClassName -Puttype CreateOnly -Argument $arglist
}