Have you tried using "Real64" instead of "String" as the CimType?
Storing double value in WMI
Hi,
I am tying to get the file size of the Outlook OST file, convert it to GB and storing it in WMI. I may store it in string and it will be working. But I am trying to store it with decimals. And I am losing the decimals.
If ($classOST -ine $null) {Remove-WmiObject -Class $Str_ClassNameOST}
[String]$Str_ClassNameOST="Outlook_OST" #Nom de la classe
$WMI_ClassOST = ""
$WMI_ClassOST = New-Object System.Management.ManagementClass("Root\cimv2", $null, $null)
$WMI_ClassOST.name = $Str_ClassNameOST
$classOST = Get-WmiObject -Class $Str_ClassNameOST -List -Namespace 'root\cimv2';
#OST
$colItemsOST = $null
$colItemsOST = (Get-ChildItem "$env:systemdrive\Users\xxxx\AppData\Local\Microsoft\Outlook" -Include *.OST -recurse -Force -ErrorAction SilentlyContinue)
If ($colItemsOST -ine $null) {
Foreach ($OST in $colItemsOST) {
$arglistOST = @{
Name = $($_.Name) #Profile name
OST = $($OST.name).ToString() #Name of the OST
#Size = [math]::Round($OST.length / 1GB,3).ToString() #Size of the OST
Size = [math]::Round($OST.length / 1GB,3) #Size of the OST
LastWrite=$($ost.LastWriteTime).tostring('yyyy-MM-dd hh:mm') #When that profil was evaluate?
}
$WMI_ClassOST.Properties.Add("Name", [System.Management.CimType]::String, $false)
$WMI_ClassOST.Properties["Name"].Qualifiers.Add("key", $true)
$WMI_ClassOST.Properties.Add("OST", [System.Management.CimType]::String, $false)
$WMI_ClassOST.Properties["OST"].Qualifiers.Add("key", $true)
#$WMI_ClassOST.Properties.Add("Size", [System.Management.CimType]:: String, $false)
$WMI_ClassOST.Properties.Add("Size", [System.Management.CimType]:: String, $false)
$WMI_ClassOST.Properties["Size"].Qualifiers.Add("key", $true)
$WMI_ClassOST.Properties.Add("LastWrite", [System.Management.CimType]::String, $false)
$WMI_ClassOST.Properties["LastWrite"].Qualifiers.Add("key", $true)
$WMI_ClassOST.Put()
Set-WmiInstance -Class $Str_ClassNameOST -Puttype CreateOnly -Argument $arglistOST
}
}
In this example, arglistOST has a size value of 1,025:
[DBG]: PS C:\WINDOWS\system32>> $arglistOST
Name Value
OST xxx.ost
LastWrite 2020-10-21 01:01
Name
Size 1,025
How may I store the size in numerical value?
Thanks
2 answers
Sort by: Most helpful
-
-
Francois 176 Reputation points
2020-10-21T19:21:47.123+00:00 Hi,
Exception lors de l'appel de « Add » avec « 2 » argument(s) : « La propriété ne peut pas être une clé »
Au caractère C:\Sovgarde\InventaireDesProfils1.0_Frv1\InventaireDesProfils1.0_Frv1.ps1:1447 : 29- ... $WMI_ClassOST.Properties["Size"].Qualifiers.Add("key", $t ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [], MethodInvocationException
- FullyQualifiedErrorId : ManagementException #$WMI_ClassOST.Properties.Add("Size", [System.Management.CimType]:: String, $false) $WMI_ClassOST.Properties.Add("Size", [System.Management.CimType]:: Real64, $false) $WMI_ClassOST.Properties["Size"].Qualifiers.Add("key", $true)
Error ADD with 2 arguments. The property cannot be a key
May be the issue is about: [System.Management.CimType]?