Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting VBScript's Left Function

Windows PowerShell

Definition: Returns a specified number of characters from the left side of a string.


What’s that? You want to know if it’s possible to use Windows PowerShell to return the first x characters in a string? Of course it is: all you have to do is call the Substring method, passing two parameters: the starting character (with 0 being the first character position) and the number of characters to return. For example, this command assigns the letters of the alphabet to a variable named $a, then uses Substring to reassign $a just the first three letters in the string:

$a = $a.substring(0,3)

When you run this command and then echo back the value of $a you should get the following:


Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft