【发布时间】:2019-04-30 01:00:32
【问题描述】:
我需要在不修改实际 AD 属性值的情况下使用 Active Directory 中的一些国际电话区号格式修改以下代码:
$defaultTelephone = '1800 552 001'
#Get Active Directory information for the currently logged on user
$sysInfo = New-Object -ComObject 'ADSystemInfo'
$userDN = $sysInfo.GetType().InvokeMember('UserName', 'GetProperty', $null, $sysInfo, $null)
$adUser = [ADSI]"LDAP://$($userDN)"
[void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($sysInfo)
#Get the phone number from the Active Directory and assign it into the International phone country code format
$IntlPhoneNumber = $(If ($ADUser.telephoneNumber) { $ADUser.telephoneNumber.ToString() }
Else { $defaultTelephone })
$IntlPhoneNumber
在上面的脚本中,它从现在设置为 08 8211 8911 的 AD 属性中提取信息。
我想显示为 $IntlPhoneNumber 的值是 + 1 8 8211 8911
所以我需要:
- 添加 +1 作为国家代码
- 从变量中删除 0,但不删除或修改 Active Directory 值。
- 如果电话号码不是2digits 4digits 4digits的形式,则显示为无需更改为+1 Country Code并删除零。
【问题讨论】:
标签: regex powershell scripting active-directory windows-scripting