Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Convert-StringToInt
- {
- process
- {
- #Store for easier use.
- $object = $_
- #The properties that we'll support converting.
- $convertables = 'TotalDeletedItemSize','TotalItemSize','DatabaseSize','FolderSize','FolderAndSubfolderSize','TopSubjectSize'
- #Collect the property list.
- $properties = $object | Get-Member -MemberType Property | select -ExpandProperty name
- #Create a new object.
- $newObject = New-Object -TypeName PSObject
- #Go through each property and convert if necessary.
- foreach ($property in $properties)
- {
- if($convertables -contains $property)
- {
- $oldValue = $object.$property
- #Pull out the stuff we're intersted in and remove commas and the like.
- $oldValue -match '\(\w.*' | out-null
- $m = $($matches[0] -replace '^\(|\s.*|,')
- #If our result is null we store a 0
- if($m -match 'temp' -or $m -like $null)
- {
- $newObject | Add-Member -Name $property -Value 0 -MemberType 'NoteProperty'
- continue
- }
- #Convet the string to bytes
- [int64]$bytes = $m
- $newObject | Add-Member -Name $property -Value $bytes -MemberType 'NoteProperty'
- }
- else
- {
- $newObject | Add-Member -Name $property -Value $object.$property -MemberType 'NoteProperty'
- }
- }
- #Return our new object.
- Write-Output $newObject
- }
- } #END Convert-StringToInt
Advertisement
Add Comment
Please, Sign In to add comment