【问题标题】:There is no user session data for the user within the specified date range指定日期范围内没有用户的用户会话数据
【发布时间】:2018-06-11 20:58:30
【问题描述】:

我正在使用以下查询从 o365 skype for business service 检索指定日期范围内的用户会话信息。

$mbxes = Get-CsOnlineUser | select UserPrincipalName
$startTime = "5/1/2018"
foreach ($mbx in $mbxes) {
  Get-CsUserSession -User $mbx -StartTime $startTime
}

运行此查询会为我正在检索的所有邮箱提供以下警告:

WARNING: There is no user session data for the user @{UserPrincipalName=account1@companyX.onmicrosoft.com} within the specified date range 01/05/2018 00:00:00 -07:00 to
11/06/2018 05:22:31 -07:00.

但是当我只是运行这个命令时:

$mbxes = "account1@companyX.onmicrosoft.com"
$startTime = "5/1/2018"
foreach ($mbx in $mbxes) {
  Get-CsUserSession -User $mbx -StartTime $startTime
}

我正在获取所有会话数据来响应此邮箱。 我想知道为什么当我用所有邮箱地址创建一个变量时,即使会话数据存在,也没有给我返回数据。

【问题讨论】:

    标签: powershell


    【解决方案1】:

    在您的第一个命令中包含| select UserPrincipalName。这会将$mboxes 分配为仅具有UserPrincipalName 属性的对象数组。

    从第二个命令看来,Get-CsUserSession 期望 -User 参数是一个字符串,但您仍在传递一个对象。您可能可以通过以下任何方式解决:

    UserPrincipalName 展开为字符串,那么你就有了一个字符串数组:

    $mbxes = Get-CsOnlineUser | select -ExpandProperty UserPrincipalName
    $startTime = "5/1/2018"
    foreach ($mbx in $mbxes) {
      Get-CsUserSession -User $mbx -StartTime $startTime
    }
    

    另一种扩展获取字符串数组的方法:

    $mbxes = (Get-CsOnlineUser).UserPrincipalName
    $startTime = "5/1/2018"
    foreach ($mbx in $mbxes) {
      Get-CsUserSession -User $mbx -StartTime $startTime
    }
    

    获取会话时显式选择属性:

    $mbxes = Get-CsOnlineUser | select UserPrincipalName
    $startTime = "5/1/2018"
    foreach ($mbx in $mbxes) {
      Get-CsUserSession -User $mbx.UserPrincipalName -StartTime $startTime
    }
    

    【讨论】:

      【解决方案2】:

      用户:@{UserPrincipalName=account1@companyX.onmicrosoft.com} 不是有效的 userPrincipalName,

      改变这个:

      $mbxes = Get-CsOnlineUser | select UserPrincipalName
      

      收件人:

      $mbxes = Get-CsOnlineUser | select -Expand UserPrincipalName
      

      见:https://blogs.msdn.microsoft.com/powershell/2009/09/13/select-expandproperty-propertyname/

      【讨论】:

      • 或使用(Get-CsOnlineUser).UserPrincipalName
      • @Avshalom 非常感谢您的回答!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多