我正在编写一个简单的PowerShell脚本,该脚本使用“Get-ADUser”cmdlet从Active Directory中获取某些字段,并将它们输出到CSV文件,这样可以正常工作:
Get-ADUser -filter * -properties Division,Department,EmployeeID,GivenName,Sn,C,Title,Mail,ExtensionAttribute3,ExtensionAttribute4,SamAccountName -server myADserver.domain.com:3268 | select Division,Department,EmployeeID,GivenName,Sn,C,Title,Mail,ExtensionAttribute3,ExtensionAttribute4,SamAccountName | Export-Csv -notype C:\Security-ActiveDirectory.csv
当我将“SamAccouontName”字段输出到CSV文件时,我希望将其转换为全部大写字母。我尝试应用ToUpper()和Upper(字符串)方法,但它们给我语法错误:
Get-ADUser -filter * -properties Division,Department,EmployeeID,GivenName,Sn,C,Title,Mail,ExtensionAttribute3,ExtensionAttribute4,SamAccountName -server myADserver.domain.com:3268 | select Division,Department,EmployeeID,GivenName,Sn,C,Title,Mail,ExtensionAttribute3,ExtensionAttribute4,ToUpper().SamAccountName | Export-Csv -notype C:\Security-ActiveDirectory.csv
Get-ADUser -filter * -properties Division,Department,EmployeeID,GivenName,Sn,C,Title,Mail,ExtensionAttribute3,ExtensionAttribute4,SamAccountName -server myADserver.domain.com:3268 | select Division,Department,EmployeeID,GivenName,Sn,C,Title,Mail,ExtensionAttribute3,ExtensionAttribute4,Upper(SamAccountName) | Export-Csv -notype C:\Security-ActiveDirectory.csv
任何人都可以帮助我如何将该字段设为大写并仍然导出到CSV文件?
谢谢! 布赖恩
答案 0 :(得分:5)
你可以这样做:
Get-ADUser -filter * -properties Division,Department,EmployeeID,GivenName,Sn,C,Title,Mail,ExtensionAttribute3,ExtensionAttribute4,SamAccountName -server myADserver.domain.com:3268 |
select Division,Department,EmployeeID,GivenName,Sn,C,Title,Mail,ExtensionAttribute3,ExtensionAttribute4,@{Label = 'SamAccountName' ; Expression = {$_.SamAccountName.ToUpper()}} |
Export-Csv -notype C:\Security-ActiveDirectory.csv