Storing double value in WMI

Francois 176 Reputation points
2020-10-21T17:05:51.15+00:00

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

Windows Server Management
Windows Server Management
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Management: The act or process of organizing, handling, directing or controlling something.
415 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,272 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 43,926 Reputation points
    2020-10-21T18:11:48.86+00:00

    Have you tried using "Real64" instead of "String" as the CimType?

    0 comments No comments

  2. 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]?