Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell script delete first character in output

Tags:

powershell

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
like image 275
user3415777 Avatar asked Feb 14 '23 12:02

user3415777


2 Answers

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) }
like image 115
Frode F. Avatar answered Feb 24 '23 09:02

Frode F.


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

Get-User $_ | Select @{N="myAccountName";E={$_.sAMAccountName).substring(1)}}
like image 31
jon Z Avatar answered Feb 24 '23 10:02

jon Z