У меня есть сценарий Powershell, который при входе в систему создает адреса электронной почты Outlook (спасибо Джоэлу Коэльо). Все работает нормально, за исключением получения номера мобильного телефона:
$signature = $rawTemplate -replace $mobilePlaceHolder,$ADUser.mobile
$rawTemplate = $signature
Это всегда возвращает пустое значение, $ mobilePlaceHolder был заменен, но ничего. Он заменяется, что подтверждается строкой:
$logline = 'Replaced ' + $mobilePlaceHolder + ' with ' + $ADUser.mobile
, которая показывает, что он ничем не заменен. Мобильный атрибут правильный, он находится в разделе «Атрибуты» в AD. Это также проявляется, когда я занимаюсь подготовкой. Все остальные параметры работают, но я не могу понять, почему это не работает. Помощь очень ценится.
Полный код: -
$logfile = "D:\CreateSignaturelog.log"
# Gets the path to the user appdata folder
date > $logfile
$AppData = (Get-Item env:appdata).value
$logline = 'My appdata folder is at ' + $AppData
$logline >> $logfile
# This is the default signature folder for Outlook
$localSignatureFolder = $AppData+'\Microsoft\Signatures'
# This is a shared folder on your network where the signature template should be
$templateFilePath = "\\nz-sp-ap1\spgeneral\Standard Documents\templates"
$logline = 'Template file path is at ' + $templateFilePath
$logline >> $logfile
# Get the current logged in username
$userName = $env:username
$logline = 'My user name is ' + $username
$logline >> $logfile
# The following 5 lines will query AD and get an ADUser object with all information
$filter = "(&(objectCategory=User)(samAccountName=$userName))"
$searcher = New-Object System.DirectoryServices.DirectorySearcher
$searcher.Filter = $filter
$ADUserPath = $searcher.FindOne()
$ADUser = $ADUserPath.GetDirectoryEntry()
$namePlaceHolder = "DISPLAY_NAME"
$FullName = $ADUser.DisplayName -replace " ", " "
$rolePlaceHolder = "ROLE"
$emailPlaceHolder = "MAILTO"
$phonePlaceHolder = "PHONE1"
$mobilePlaceHolder = "PHONE2"
$addressPlaceHolder = "ADDRESS"
$entiremobilerow = '<tr><td colspan="2" class="style2">Mobile: PHONE2</td></tr>'
$rawTemplate = get-content $templateFilePath"\Emailtemplate.html"
$signature = $rawTemplate -replace $namePlaceHolder,$FullName
$rawTemplate = $signature
$logline = 'Replaced ' + $namePlaceHolder + ' with ' + $FullName
$logline >> $logfile
$signature = $rawTemplate -replace $rolePlaceHolder,$ADUser.description
$rawTemplate = $signature
$logline = 'Replaced ' + $rolePlaceHolder + ' with ' + $ADUser.description
$logline >> $logfile
$signature = $rawTemplate -replace $emailPlaceHolder,$ADUser.mail
$rawTemplate = $signature
$logline = 'Replaced ' + $emailPlaceHolder + ' with ' + $ADUser.mail
$logline >> $logfile
$signature = $rawTemplate -replace $phonePlaceHolder,$ADUser.telephonenumber
$rawTemplate = $signature
$logline = 'Replaced ' + $phonePlaceHolder + ' with ' + $ADUser.telephonenumber
$logline >> $logfile
If ($ADUser.mobile = ""){
$signature = $rawTemplate -replace $entiremobilerow,""
$rawTemplate = $signature
$logline = 'Replaced ' + $entiremobilerow + ' with nothing.'
$logline >> $logfile
}
$signature = $rawTemplate -replace $mobilePlaceHolder,$ADUser.MobilePhone
$rawTemplate = $signature
$logline = 'Replaced ' + $mobilePlaceHolder + ' with ' + $ADUser.MobilePhone
$logline >> $logfile
$logline = 'ExtensionAttribute1 is "+ ADUser.ExtensionAttribute1
$logline >> $logfile
$signature = $rawTemplate -replace $addressPlaceHolder,$ADUser.physicalDeliveryOfficeName
$rawTemplate = $signature
$logline = 'Replaced ' + $addressPlaceHolder + ' with ' + $ADUser.physicalDeliveryOfficeName
$logline >> $logfile
# Save it as <username>.htm
$fileName = $localSignatureFolder + "\" + $ADUser.DisplayName + ".htm"
$signature > $fileName
$logline = 'Saved ' + $filename
$logline >> $logfile
#Change to first name
$signature = $rawTemplate -replace $FullName,$ADUser.givenName
$rawTemplate = $signature
# Save it as <firstname>.html
$fileName = $localSignatureFolder + "\" + $ADUser.givenName + ".htm"
$signature > $fileName
$logline = 'Saved ' + $fileName
$logline >> $logfile