gpt4 book ai didi

powershell - Powershell get-aduser提取带有扩展属性的选择对象问题

转载 作者:行者123 更新时间:2023-12-03 01:03:48 26 4
gpt4 key购买 nike

除家用电话和移动电话外,此脚本非常有用。如果extensionAttribute为空,那么我希望文件中的电话号码带有“”。否则它将有一个电话号码,前面有一个1。

空白时返回的是“1”。我很困惑为什么其他部分无论扩展属性为空都在执行。

Get-ADUser -filter {(enabled -eq $True) -and (extensionAttribute4 -eq "LoadedFromInterface")} -Properties Name, GivenName,SN,Office, Mobile, emailaddress,Department, Title, samaccountname, manager,officephone,homephone,extensionAttribute5,extensionAttribute6 | `
Select-object @{Name='User';Expression={$_."SamAccountName"}},
@{Name='First Name';Expression={$_."GivenName"}},
@{Name='Last Name';Expression={$_."SN"}},
@{Name='Site';Expression={$_."Office"}},
@{Name='Work Email';Expression={$_."emailAddress"}},
@{N='Home Email';E={''}},
@{Name='Work Phone';Expression={if ($_."officephone" -eq $null){""} else {'1'+ $_."officephone" -replace "\D"}}},
@{Name='Home Phone';Expression={if ($_."extensionAttribute5" -notlike '*'){""} else {'1'+ $_."extensionAttribute5" -replace "\D"}}},
@{Name='Mobile Phone';Expression={if ($_."extensionAttribute6" -notlike '*'){""} else {'1'+ $_."extensionAttribute6" -replace "\D"}}},
@{N='Mobile Phone 2';E={''}},
@{Name='Personal Mobile Phone';Expression={''}},
@{Name='Personal Mobile Phone 2';Expression={''}},
@{Name='SMS Phone';Expression={''}},
@{Name='SMS Phone 2';Expression={''}},
@{Name='Personal SMS Phone';Expression={''}},
@{Name='Personal SMS Phone 2';Expression={''}},
@{Name='Pager';Expression={''}},
@{Name='Pager Provider';Expression={''}},
@{Name='Fax';Expression={''}},
@{Name='IVR';Expression={''}},
Department,
@{Name='Job Title';Expression={$_."title"}},
@{N='Manager';E={(Get-ADUser $_.Manager).Name}} | `
Export-CSV -NoTypeInformation c:\temp\User_Input.csv

寻找一些发现问题的帮助。

最佳答案

About Wildcards:*匹配零个或多个字符

    PS > $null -like '*'
True
PS > 'random text' -like '*'
True
PS > '' -like '*' # empty string
True

Try this [System.String]::IsNullOrEmpty()
@{Name='Home Phone';Expression={if ([System.String]::IsNullOrEmpty($_."extensionAttribute5")){""} else {'1'+ $_."extensionAttribute5" -replace "\D"}}}, 
@{Name='Mobile Phone';Expression={if ([System.String]::IsNullOrEmpty($_."extensionAttribute6")){""} else {'1'+ $_."extensionAttribute6" -replace "\D"}}},

关于powershell - Powershell get-aduser提取带有扩展属性的选择对象问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52192723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com