附加/合并文本以管道“选择”结果

时间:2019-01-30 02:21:13

标签: powershell

当我执行以下powershell脚本时,

Site_ForList

它将返回

Import-Module activedirectory
Get-ADPrincipalGroupMembership someuser | select Name

如何返回附加“ _1234”的结果,如:

Name
----
Domain Users

1 个答案:

答案 0 :(得分:2)

您可以使用计算所得的属性。

from collections import defaultdict

recs = defaultdict(list)

for item in test:
    name = os.path.basename(item)
    no_ext = name.split('.')[0]
    recs[no_ext].append(name)

to_delete = [val for v in recs.values() for val in v if len(v) >= 2 and val.endswith('.txt')]

for item in to_delete:
    os.remove(os.path.join(pathforRemove, item))