Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

convert member property to type int

Posted on 2014-02-20
4
Medium Priority
?
382 Views
Last Modified: 2014-02-20
Hello EE,

I have a member in a system.object of typename

TypeName: System.Management.Automation.PSCustomObject

Name            MemberType   Definition                          
----            ----------   ----------                          
Equals          Method       bool Equals(System.Object obj)      
GetHashCode     Method       int GetHashCode()                  
GetType         Method       type GetType()                      
ToString        Method       string ToString()                  
name            NoteProperty System.String name=tbl_Core_Auditing
TableDataSizeMB NoteProperty System.String TableDataSizeMB=5283  

As you can see there is tabledatasizemb as type system.string , i wish to convert this to int32 for each element in the array
0
Comment
Question by:davesnb
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39874241
you can use Int32.Parse(yourvariable.TabelDataSizeMB), this should return the int32 value for the string...
http://msdn.microsoft.com/en-us/library/system.int32.parse%28v=vs.110%29.aspx
0
 

Author Comment

by:davesnb
ID: 39874388
$tblsize = import-csv C:\Scripts\dump\tblsize\$datelog.csv
$tblsize | Int32.Parse($tblsize.TableDataSizeMB)

Open in new window


Sorry not familiar with the syntax here , returns " The term 'Int32.Parse' is not recognized as the name of a cmdlet.." when using Int32.Parse($tblsize.TabelDataSizeMB)
0
 
LVL 41

Accepted Solution

by:
footech earned 2000 total points
ID: 39874425
If the results from Import-CSV are stored in a variable $array, you can use the following.
$array | ForEach { $_.TableDataSizeMB = [int32]$_.TableDataSizeMB }

Open in new window


Or you could just treat the property as an int32 later in your script when doing comparisons, etc.
0
 

Author Closing Comment

by:davesnb
ID: 39874438
great thanks
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question