ForEachLoop在PowerShell中不起作用,但是我拥有完全访问权限,这是什么问题?

问题描述 投票:0回答:1

enter image description here

 Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$count
#$farm = Get-SPFarm
$siteList = Get-SPSite -Limit 1
$serviceContext = Get-SPServiceContext($siteList[0])
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($servicecontext)
$profiles = $profileManager.GetEnumerator()
foreach ($hi in $profiles) {
    if([string]::IsNullOrEmpty($hi["AboutMe"].Value) -eq $false){
        write-host "Acount Name:"$hi.AccountName"|AboutMe:"$hi["AboutMe"].Value
        $count++
    }
}
write-host $count

我在foreachloop中不断收到错误,以下错误。当我输入SP-Farm时,我会把所有东西都找回来,所以不会成为访问问题?

UserProfileDBCache_WCFLogging :: ProfileDBCacheServiceClient.GetUserData threw exception: Access is denied.
At line:8 char:10
+ foreach ($hi in $profiles) {
+          ~~~
    + CategoryInfo          : OperationStopped: (:) [], UserProfileApplicationNotAvailableException
    + FullyQualifiedErrorId : Microsoft.Office.Server.UserProfiles.UserProfileApplicationNotAvailableException
powershell sharepoint azure-ad-graph-api powershell-ise
1个回答
0
投票
以下PowerShell供您参考。

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue $count $siteList = Get-SPSite -Limit 1 $serviceContext = Get-SPServiceContext($siteList[0]) $profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext) $profiles = $profileManager.GetEnumerator() foreach ($profile in $profiles) { if([string]::IsNullOrEmpty($profile["AboutMe"].Value) -eq $false){ write-host "Acount Name:"$profile.AccountName"|AboutMe:"$profile["AboutMe"].Value $count++ } } write-host $count

enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.