5

How would I delete the first line in the output from this command? If the output is A123456, I just want it to show me 123456 with the A.

Get-User $_ | Select sAMAccountName
2
  • What is the Get-User command? That doesn't seem to work for me. Commented Mar 13, 2014 at 19:00
  • Do you just want the sAMAccountName string, or do you want an object with the sAMAccountName property? Commented Mar 13, 2014 at 19:00

4 Answers 4

5

Just get the substring starting at the second letter(index 1).

Get-User $_ | Select @{n="AccountName";e={$_.sAMAccountName.Substring(1)}}

If you just need the value, you could do it like this:

Get-User $_ | % { $_.sAMAccountName.Substring(1) }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Frode. I just needed the value. I am not that familar with using strings but appreacite your expertise.
2

Substring(1) returns a substring containing all chars after the first one.

Get-User $_ | Select @{N="myAccountName";E={$_.sAMAccountName).substring(1)}}

Comments

2

You can remove the first character with the -replace operator:

(Get-User $_ | select -Expand sAMAccountName) -replace '^.'

Or

Get-User $_ | select @{n='sAMAccountName';e={$_.sAMAccountName -replace '^.'}}

if you want to keep objects rather than strings.

Comments

0
$str = "@123456";
$str = $str.Substring(1,($str.Length-1));
$str;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.