To start, we will simply declare a new object,
Simple enough. Now we have a string object named $string. To get the type of the object, there are two immediate approaches to use:$string = "string"
For such a small piece of information, these are very verbose ways to get down to brass tacks. To take it a step further, we can look at the underlying assembly with this command:$string.GetType()IsPublic IsSerial Name BaseType-------- -------- ---- --------True True String System.Object$string | Get-MemberTypeName: System.StringName MemberType Definition---- ---------- ----------Clone Method System.Object Clone()CompareTo Method int CompareTo(System.Object value), int CompareTo(string strB)Contains Method bool Contains(string value)CopyTo Method System.Void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)EndsWith Method bool EndsWith(string value), bool EndsWith(string value, System.StringComparison comparisonType...Equals Method bool Equals(System.Object obj), bool Equals(string value), bool Equals(string value, System.Str...GetEnumerator Method System.CharEnumerator GetEnumerator()GetHashCode Method int GetHashCode()GetType Method type GetType()GetTypeCode Method System.TypeCode GetTypeCode()IndexOf Method int IndexOf(char value), int IndexOf(char value, int startIndex), int IndexOf(char value, int s...IndexOfAny Method int IndexOfAny(char[] anyOf), int IndexOfAny(char[] anyOf, int startIndex), int IndexOfAny(char...Insert Method string Insert(int startIndex, string value)IsNormalized Method bool IsNormalized(), bool IsNormalized(System.Text.NormalizationForm normalizationForm)LastIndexOf Method int LastIndexOf(char value), int LastIndexOf(char value, int startIndex), int LastIndexOf(char ...LastIndexOfAny Method int LastIndexOfAny(char[] anyOf), int LastIndexOfAny(char[] anyOf, int startIndex), int LastInd...Normalize Method string Normalize(), string Normalize(System.Text.NormalizationForm normalizationForm)PadLeft Method string PadLeft(int totalWidth), string PadLeft(int totalWidth, char paddingChar)PadRight Method string PadRight(int totalWidth), string PadRight(int totalWidth, char paddingChar)Remove Method string Remove(int startIndex, int count), string Remove(int startIndex)Replace Method string Replace(char oldChar, char newChar), string Replace(string oldValue, string newValue)Split Method string[] Split(Params char[] separator), string[] Split(char[] separator, int count), string[] ...StartsWith Method bool StartsWith(string value), bool StartsWith(string value, System.StringComparison comparison...Substring Method string Substring(int startIndex), string Substring(int startIndex, int length)ToCharArray Method char[] ToCharArray(), char[] ToCharArray(int startIndex, int length)ToLower Method string ToLower(), string ToLower(System.Globalization.CultureInfo culture)ToLowerInvariant Method string ToLowerInvariant()ToString Method string ToString(), string ToString(System.IFormatProvider provider)ToUpper Method string ToUpper(), string ToUpper(System.Globalization.CultureInfo culture)ToUpperInvariant Method string ToUpperInvariant()Trim Method string Trim(Params char[] trimChars), string Trim()TrimEnd Method string TrimEnd(Params char[] trimChars)TrimStart Method string TrimStart(Params char[] trimChars)Chars ParameterizedProperty char Chars(int index) {get;}Length Property System.Int32 Length {get;}
This gives us a little info, but, we can dig deeper. What is interesting here is the fact that, if you use tab completion, these members are not accessible. Key takeaway? Sometimes you have to force PowerShell to tell you what else is out there for a given object. For example, the simply .Assembly property returns a very different set of members if you pipe it to | Select *,$string.GetType().AssemblyGAC Version Location--- ------- --------True v4.0.30319 C:WindowsMicrosoft.NETFramework64v4.0.30319mscorlib.dll
$string.GetType().Assembly | select *CodeBase : file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dllFullName : mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089EntryPoint :Evidence : {<System.Security.Policy.GacInstalled version="1"/>, <System.Security.Policy.Hash version="2"><hash algorithm="SHA1"value="629DA705B1D63F713B6237815E8AAE169209BD36"/><hash algorithm="SHA256"value="7F5383D5CA77A8BADF685D5464E2367D76207A2445587A4B1424E171561EAEBC"/><hash algorithm="MD5"value="6ECA29D69B4E2DDBFC1E824A8F0BFD1A"/></System.Security.Policy.Hash>, <StrongName version="1"Key="00000000000000000400000000000000"Name="mscorlib"Version="4.0.0.0"/>
0 comments:
Post a Comment