Methods allow you to examine, compare and format many properties of a PowerShell Object (often referenced via a variable).
Discover the methods available for an object with Get-Member
For example, an integer: 123 | get-member will return the methods: CompareTo, Equals, GetHashCode, GetType, GetTypeCode, ToString
Using some of those methods:
(123).equals(456) will return false
(123).CompareTo(150)will return -1
(123).ToString()
Note that CompareTo() differs from equals() in that it returns different values if the item is greater than or less than.
Finding methods for a string: "The world is everlasting" | get-member will return the methods: Clone, CompareTo, Contains, CopyTo, EndsWith, Equals,GetEnumerator, GetHashCode, GetType, GetTypeCode, GetChars, GetLength, IndexOf, IndexOfAny, Insert, IsNormalised, LastIndexOf, LastIndexOfAny, Normalize, PadLeft, PadRight, Remove, Replace,Split, StartsWith, Substring, ToCharArray, ToLower, ToLowerInvariant, ToString, ToUpper,ToUpperInvariant, Trim,TrimEnd,TrimStart, Chars, Length
Examples:
($myStringVar1).ToLower()
($myStringVar1).equals($myStringVar2)
($myStringVar1).CompareTo($myStringVar2)
($myStringVar1).PadRight() + "**"
("a b c").split("b")
List of PowerShell Methods (not complete, as explained above not all methods are available for all Objects):
AddDays()
AddHours()
Clone()
Create()
Chars(IntIndex) {get;}
CompareTo(Object )
CompareTo(String)
Contains(strValue)
CopyTo(IntSourceIndex, strDestination, IntDestinationIndex, IntCount)
Delete()
EndsWith(String [, StringComparisonType])
Equals(Object)
Equals(strValue)
Equals(strValue, StringComparisonType)
get_CreationTime()
get_CreationTimeUtc()
GetEnumerator()
get_FullName()
get_LastAccessTime()
get_LastWriteTime()
GetType()
get_Chars(IntIndex)
get_Length()
IndexOf(StrValue, IntStartIndex, IntCount)
IndexOfAny(strAnyOf, [IntStartIndex, IntCount])
Insert(IntStartIndex, String value)
Length {get;}
PadLeft(IntTotalWidth [, StrPaddingChar] )
PadRight(IntTotalWidth [, StrPaddingChar] )
Remove(IntStartIndex [, IntCount])
Replace(strOldChar, strNewChar)
Split(strSeparator [,MaxSubstrings])
StartsWith(strValue [,strComparisonType)
Substring(IntStartIndex[, IntLength])
ToCharArray([IntStartIndex, IntLength])
ToLower()
ToString()
ToUpper()
Trim(strTrimChars])
TrimEnd(strTrimChars)
TrimStart(strTrimChars)
“There nearly always is method in madness. It's what drives men mad, being methodical” ~ G. K. Chesterton
Related:
Get-Item Variable:
Get-Variable
© Copyright SS64.com 1999-2013
Some rights reserved