Solved

convert member property to type int

Posted on 2014-02-20
4
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 40

Accepted Solution

by:
footech earned 500 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
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 antispam), the admini…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

623 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