I have an interesting issue that I am hoping the crowd can help with. A Powershell script that I am running on my jump box is completes without error. When I run it on the production server, it errors out with
At D:\Scripts\Groups\MS_Student_Group_Update.ps1:9 char:265
+ ... ountName, @{name=â€
+ ~
You must provide a value expression following the '-join' operator.
Both are MSServer 2016.
Here is the script
Function writeLog {
Param ([string]$logstring)
Add-content $Logfile -value $logstring
}
$date = get-date -f MMddyyyy
$Logfile = 'D:\Powershell\Logs\googleEmailGroup_AD_MS' + $date + '.log'
$ldapSearcher = get-aduser -ldapfilter '(&(objectCategory=person)(objectClass=user)(description=*middle*)(cn=S*)(!userAccountControl:1.2.840.113556.1.4.803:=2))' -properties MemberOf |select name,SamAccountName, @{name=”MemberOf”;expression={$_.memberof -join “;”}}
#$test = $ldapSearcher | select -first 20
foreach($user in $ldapSearcher) {
$ErrorOccurred = $false
if($user.MemberOf -notlike "FCPS MS*") {
$user_grp = 'FCPS MS Students All'
try {
Add-adgroupmember -Identity $user_grp -Members $user.SamAccountName
}
catch {
writeLog "Failed to add $($user.SamAccountName) GoogleSyncGroup."
}
if(!$ErrorOccurred) {
writeLog "Added_to_Google_Group: $($user.samaccountname)"
}
} }