Powershell 从输出中分割线

发布于 01-17 18:41 字数 1098 浏览 2 评论 0原文

我用Powershell涉足到这里和那里,但我仍然需要一些工作。我正在尝试从文本文件的一行中获取输出,以准备使用它以迁移到具有相同用户名库的另一个域。该提取物是一个称为“ group-executives-ronly”的组名称,下一组数据是该组中的组和用户称为“ group-ectecutives-ronly”,

$variable1 = '"Group-Executives-ronly","Group Approvers for accounts;Wilson, Frank fwilson;Jorden, mike mjorden;smith, David dsmith"'

我只是在我实际使用此数据进行此数据之前显示结果其他工作。我想像这样打印每条线,但是拆分的每一个迭代对于用户名称部分都无法正常工作。

Group-Executives-ronly

Group Approvers for accounts
fwilson
mjorden
dsmith

我首先将其打破了它,

$group=$variable1.Split('"')\[1\]
$Userslist=$variable1.Split('"')\[3\]

这给第一个数组提供了group-executives-ronly和第三个数组for Accounts; dsmith

我做了另一个数组以;

$Users=$Userslist.Split(';')

拆分,这给了我所有的组/用户,所以

Group Approvers for accounts

Wilson, Frank fwilson

Jorden, mike mjorden

smith, David dsmith

我喜欢我得到了完整的组名称,但我不希望那些用户,我只需要他们的uid,这是可能的吗,我是否会犯错吗?所需的输出是

Group Approvers for accounts

fwilson

mjorden

dsmith

I dabbled here and there with PowerShell but I still need some work. I am trying to take an output from a line of a text file to get ready to use it to migrate to another domain with same user name base. The extract is a group name called "Group-Executives-ronly" and the next set of data is the groups and users in that group called "Group-Executives-ronly"

$variable1 = '"Group-Executives-ronly","Group Approvers for accounts;Wilson, Frank fwilson;Jorden, mike mjorden;smith, David dsmith"'

I am just displaying result before I actually use this data to do the other work. I would like to get each line printed like so but every iteration of split is not working well for the user name section.

Group-Executives-ronly

Group Approvers for accounts
fwilson
mjorden
dsmith

I had first broken it up with

$group=$variable1.Split('"')\[1\]
$Userslist=$variable1.Split('"')\[3\]

Which gave the first array the Group-Executives-ronly and the 3rd array Group Approvers for accounts;Wilson, Frank fwilson;Jorden, mike mjorden;smith, David dsmith

I did another array for splitting with ;

$Users=$Userslist.Split(';')

and that gave me all the group/users split like so

Group Approvers for accounts

Wilson, Frank fwilson

Jorden, mike mjorden

smith, David dsmith

I like that I got the full group name but I don't want the name of those users, I just need their UID, is that possible, am I going at it wrong? The desired output needed is

Group Approvers for accounts

fwilson

mjorden

dsmith

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一梦浮鱼2025-01-24 18:41:31

圣地亚哥·斯夸松所说的。

您很接近:从用户列表中分割“;”后,如果它包含“,”,则在空间上分割并获取最后一项,否则仅获取整个用户列表项。

PS /> $variable1 = '"Group-Executives-ronly","Group Approvers for accounts;Wilson, Frank fwilson;Jorden, mike mjorden;smith, David dsmith"'
PS /> $group=$variable1.Split('"')[1]                                                                                                      
PS /> $Userslist=$variable1.Split('"')[3]                                                                                                  
PS /> $Userslist.split(';') | %{if ($_.contains(',')){$_.split(' ')[-1]} else {$_}}                                                        
Group Approvers for accounts
fwilson
mjorden
dsmith
PS /> 

What Santiago Squarzon said.

You're close: from the userlist after splitting in ';', if it contains a ',' then split on space and grab the last item, otherwise just take the whole userlist item.

PS /> $variable1 = '"Group-Executives-ronly","Group Approvers for accounts;Wilson, Frank fwilson;Jorden, mike mjorden;smith, David dsmith"'
PS /> $group=$variable1.Split('"')[1]                                                                                                      
PS /> $Userslist=$variable1.Split('"')[3]                                                                                                  
PS /> $Userslist.split(';') | %{if ($_.contains(',')){$_.split(' ')[-1]} else {$_}}                                                        
Group Approvers for accounts
fwilson
mjorden
dsmith
PS /> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文