powershell - Sitecore Powershell get-user命令

标签 powershell sitecore sitecore7 sitecore8

我们的sitecore系统中有超过20万名用户。我需要导出满足特定条件的用户列表。我为此使用Powershell脚本,并且使用get-user命令检索用户。然后,我遍历用户列表并选择符合我的条件的用户;在我的情况下,那些年满18岁的用户。然后使用export-csv将结果写到csv文件中。我发现这需要1.5个小时才能完成。

我的问题是,有什么方法可以吸引用户并指定我的18岁以上年龄标准?字段年龄存储在自定义属性中。另外,还有其他有效的方法(除了Powershell之外)可以完成我在这里要做的事情?

这是原始代码:

function export($user)
{
    $age = $user.profile.GetCustomProperty("age")

    if{$age -gt 18)
    {
        $id = $user.profile.GetCustomProperty("id")
        $firstname = $user.profile.GetCustomProperty("first name")

        $user | select-object -property @{Name="First Name";Expression={$firstname}}, 
            @{Name="Age";Expression={$age}}, 
            @{Name="ID";Expression={$id}} |
        Export-CSV -Path c:\temp\out.csv -Append -NoTypeInformation
    }
}

$users = get-user -Filter * 

if($users -ne $null)
{
    $users | foreach {export($_)}
}

最佳答案

更新:

根据您的示例,我可以了解为什么要花这么长时间。您正在为每次迭代导出到CSV。

试试这个:

$users = Get-User -Filter * | Where-Object { $_.Profile.GetCustomProperty("age") -gt 18 } 

$property = @(
    "Name",
    @{Name="First Name";Expression={$PSItem.Profile.GetCustomProperty("first name")}}, 
    @{Name="Age";Expression={$PSItem.Profile.GetCustomProperty("age")}}, 
    @{Name="ID";Expression={$PSItem.Profile.GetCustomProperty("id")}}
)
$users | Select-Object -Property $property | Export-CSV -Path c:\temp\out.csv -Append -NoTypeInformation

旧评论:

我看得越多,我就怀疑这是否可以做到。 age属性应该被序列化并存储在配置文件中。除非有一种更快的方法来提取个人资料日期,否则我不确定还能采取什么其他措施来加快进度。

我怀疑您正在执行以下操作:
Get-User -Filter * | Where-Object { $_.Profile.GetCustomProperty("Age") -gt 18 }

我不知道比这更快的方法。

关于powershell - Sitecore Powershell get-user命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34982451/

相关文章:

powershell - 是否可以自动制作天蓝色弹性泳池秤?

Powershell 环境变量未更新

powershell - 表示 Azure DevOps 管道中的列表变量,用于 PowerShell

sitecore - 将 Sitecore 路由映射到项目/ Controller

json - 在Powershell或VBS中翻译的CURL命令

xml 数据的 sitecore 字段数据类型

c# - Sitecore DateField 的 DateTime 属性显示错误的日期

Sitecore:在页面编辑器模式下检测用户

sitecore - 是否可以在 Sitecore 页面编辑器 "component navigator"中为占位符、组件和编辑框架定义不同的图标?

javascript - Sitecore 7.2 在添加到组件区域时在组件上触发 JavaScript