删除域重新排序用户名Powershell

时间:2018-06-29 14:20:56

标签: powershell

我正在创建一个脚本,该脚本将删除域并重新排列第一个/最后一个。 将“ 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

1 个答案:

答案 0 :(得分:4)

您似乎正在做很多额外的不必要的工作。怎么样:

   spyOn(httpService, 'getData').and.returnValue(Observable.of(url));

这是假设您输入的CSV文件具有一个Import-Csv "C:\Users\tech\Desktop\naming.csv" | ForEach-Object { $_.username -replace '[^\\]+\\([^,]+), (.+)','$2 $1' } | Out-File "C:\Users\tech\Desktop\namingoutput.txt" 列,其中包含格式为username的用户名。

相关问题