删除域重新排序用户名powershell

删除域重新排序用户名powershell,powershell,Powershell,我正在创建一个脚本,它将剥离域并重新排序第一个/最后一个。 “microsoft\smith,joe”改为“joe smith”。我不能完全正确地重新订购。这就是我所拥有的: $inputcsv = import-csv "C:\Users\tech\Desktop\naming.csv" $columnget = $($inputcsv.username) $shortname = $columnget.replace("microsoft\" , " ") $removecomma = $

我正在创建一个脚本,它将剥离域并重新排序第一个/最后一个。 “microsoft\smith,joe”改为“joe smith”。我不能完全正确地重新订购。这就是我所拥有的:

$inputcsv = import-csv "C:\Users\tech\Desktop\naming.csv"
$columnget = $($inputcsv.username)

$shortname = $columnget.replace("microsoft\" , " ")
$removecomma = $shortname.replace("," , " ")

foreach ($line in $columnget){$shortname}
foreach ($line in $shortname){$removecomma}
$thestring = foreach ($line in $removecomma){$line.Split(' ')[1..0]} -join ' '
$thenewstring = "$($thestring[1]+$thestring[0])" | export-csv "C:\Users\tech\Desktop\namingoutput.csv" -NoTypeInformation

你似乎在做很多不必要的额外工作。那么:

Import-Csv "C:\Users\tech\Desktop\naming.csv" | ForEach-Object {
  $_.username -replace '[^\\]+\\([^,]+), (.+)','$2 $1'
} | Out-File "C:\Users\tech\Desktop\namingoutput.txt"

这是假设您的输入CSV文件有一个
username
列,其中包含格式为
domainname\last,first
的用户名。您似乎正在做大量额外的不必要的工作。那么:

Import-Csv "C:\Users\tech\Desktop\naming.csv" | ForEach-Object {
  $_.username -replace '[^\\]+\\([^,]+), (.+)','$2 $1'
} | Out-File "C:\Users\tech\Desktop\namingoutput.txt"

这是假设您的输入CSV文件有一个
username
列,其中包含格式为
domainname\last,first

的用户名。这真的很有效。我看不出如何一次完成所有步骤。我知道你是怎么做到的。没错,有一个用户名列,上面有domain\last,first。是的。这真的很有效。我看不出如何一次完成所有步骤。我知道你是怎么做到的。没错,有一个用户名列,上面有domain\last,first。