Powershell 为什么当有更多变量时,about me变量只计算为1?
该代码用于计算用户在用户配置文件服务中填写“关于我”部分的次数。但是,变量Powershell 为什么当有更多变量时,about me变量只计算为1?,powershell,sharepoint,active-directory,powershell-ise,Powershell,Sharepoint,Active Directory,Powershell Ise,该代码用于计算用户在用户配置文件服务中填写“关于我”部分的次数。但是,变量abtMeNonEmpty仅在有更多变量时计数1?问题是什么 $TestGroup = Get-ADUser -Filter * -SearchBase "DC=name,DC=name,DC=name,DC=name" -Properties SAMAccountName | Where-Object {$_.Enabled -eq $false} | Select-Object SAMAccountName $ser
abtMeNonEmpty
仅在有更多变量时计数1
?问题是什么
$TestGroup = Get-ADUser -Filter * -SearchBase "DC=name,DC=name,DC=name,DC=name" -Properties SAMAccountName | Where-Object {$_.Enabled -eq $false} | Select-Object SAMAccountName
$serviceContext = Get-SPServiceContext -Site "http://blahblahblah"
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext)
$profiles = $profileManager.GetEnumerator()
#loops through all profiles in the profile manager
foreach ($prof in $profiles) {
$str_abt = $prof["AboutMe"].value
$str_prov = $prof["Province"].value
#checks if user is active
if ($prof.AccountName.IndexOf($TestGroup) -eq -1){
$numOfActiveSP++
#checks number of about me filled out
if($str_abt) {
$abtMeNonEmpty++
}
#checks how many provinces filled out also have about me
if($str_prov -and $str_abt) {
$regAboutMeNonEmpty++
$str_prov = $str_prov.ToUpper()
$str_prov = $str_prov.Replace(".", "")
$str_prov = $str_prov.Replace("-", "")
$str_prov = $str_prov.Replace(" ", "")
}
}
}
你不能只做
$profiles[“AboutMe”].count
@Lee_Dailey你知道ise中有没有内置的格式化工具吗?@shadow2020我首先需要检查用户是否被禁用($profiles[“AboutMe”]| where对象{$profiles.AccountName.IndexOf($TestGroup)-eq-1}).count
假设$prof.AccountName
类型是字符串,$TestGroup
类型是Object[]
(或PSCustomObject[]
),则$prof.AccountName.IndexOf($TestGroup)
始终返回-1
。我想,$TestGroup.SAMAccountName.IndexOf($prof.AccountName)
可以更好地工作吗?