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\racfr13\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>> $arglistOSThttps://powershell.org/forums/topic/guide-to-posting-code-2/#post-261015
Name Value
<hr />
OST xxx.ost
LastWrite 2020-10-21 01:01
Name 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\racfr13\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 <hr /> OST xxx.ost LastWrite 2020-10-21 01:01 Name
Size 1,025 and keeping the decimals.
How may I store the size in numerical value and keeping the decimals?