gpt4 book ai didi

powershell - Powershell获取列出的值

转载 作者:行者123 更新时间:2023-12-02 23:17:04 25 4
gpt4 key购买 nike

我试图从哈希表中获取值,但是我对此有些困难。$allMediafiles是一个哈希表。
这是我的代码:

$AllDoc =  ($allMediaFiles | Group-Object "video_audio" | ? {$_.name -eq 'document'}).Group

$obj2 = [pscustomobject]@{
'FileTypes' = ($AllDoc.video_audio | Group ).Name;
'Format' = ($AllDoc.Format | Group).Values ;
'O_OpenAccess' = ($AllDoc | Group-Object "SecurityTag" | ? {$_.Name -eq "O_OpenAccess"}).count;
'U_UserAccess' = ($AllDoc | Group-Object "SecurityTag" | ? {$_.Name -eq "U_UserAccess"}).count;
'S_SubscriberAccess' = ($AllDoc | Group-Object "SecurityTag" | ? {$_.Name -eq "S_SubscriberAccess"}).count;
'REVIEW_ELDP' = ($AllDoc | Group-Object "SecurityTag" | ? {$_.Name -eq "REVIEW_ELDP"}).count;
}
我的结果:
FileTypes Format           O_OpenAccess U_UserAccess S_SubscriberAccess REVIEW_ELDP
--------- ------ ------------ ------------ ------------------ -----------
document {eaf, pfsx, pdf} 0 17 2 0
我需要这样的东西:
FileTypes Format           O_OpenAccess U_UserAccess S_SubscriberAccess REVIEW_ELDP
--------- ------ ------------ ------------ ------------------ -----------
document eaf 0 14 1 0
pfsx 0 3 0 0
pdf 0 0 1 0
谢谢你的帮助!!
$Alldoc =

video_audio SecurityTag Duration Format
----------- ----------- -------- ------
document U_UserAccess eaf
document U_UserAccess eaf
document U_UserAccess eaf
document U_UserAccess eaf
document U_UserAccess eaf
document U_UserAccess eaf
document U_UserAccess eaf
document U_UserAccess eaf
document S_SubscriberAccess eaf
document U_UserAccess pfsx
document U_UserAccess eaf
document U_UserAccess eaf
document U_UserAccess eaf
document U_UserAccess eaf
document U_UserAccess pfsx
document U_UserAccess pfsx
document U_UserAccess pfsx
document U_UserAccess eaf
document S_SubscriberAccess pdf
document U_UserAccess eaf

最佳答案

您只需要再次调用Group-Object-按Format对记录进行分组-然后遍历结果:

foreach($format in $Alldoc |Group-Object -Property Format)
{
[pscustomobject]@{
# Just grab the first one - they're all identical
'FileTypes' = $format.Group[0].video_audio
# Grab the format Name from when we grouped them
'Format' = $format.Name
# For the remaining ones, simply count the number of occurences
'O_OpenAccess' = @($format.Group |? {$_.SecurityTag -eq "O_OpenAccess"}).Count
'U_UserAccess' = @($format.Group |? {$_.SecurityTag -eq "U_UserAccess"}).Count
'S_SubscriberAccess' = @($format.Group |? {$_.SecurityTag -eq "S_SubscriberAccess"}).Count
'REVIEW_ELDP' = @($format.Group |? {$_.SecurityTag -eq "REVIEW_ELDP"}).Count
}
}

关于powershell - Powershell获取列出的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63799811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com