我有一个表变量,可以像csv文件一样对待......
"SamAccountName","lastLogonTimestamp","AccountExpires","givenname","sn","distinguishedName","employeeNumber","employeeID","Description","extensionattribute8","userAccountControl"
"value1","value1","value1","value1","value1","value1","value1","value1","value1","value1","value1"
"value2","value2","value2","value2","value2","value2","value2","value2","value2","value2","value2"
"value3","value3","value3","value3","value3","value3","value3","value3","value3","value3","value3"
我想要做的是将两个标题名称givenname
更改为FirstName
,将sn
更改为LastName
。
注意:我还想更改lastLogonTimestamp
和AccountExpires
的值,但我已经有了执行此操作的工作代码。此代码如下......
$listOfBadDateValues = '9223372036854775807', '9223372036854770000', '0'
$maxDateValue = '12/31/1600 5:00 PM'
$tableFixed = $table | % {
if ($_.lastLogonTimestamp) {
$_.lastLogonTimestamp = ([datetime]::FromFileTime($_.lastLogonTimestamp)).ToString('g')
}; if (($_.AccountExpires) -and ($listOfBadDateValues -contains $_.AccountExpires)) {
$_.AccountExpires = $null
} else {
if (([datetime]::FromFileTime($_.AccountExpires)).ToString('g') -eq $maxDateValue) {
$_.AccountExpires = $null
} Else {
$_.AccountExpires = ([datetime]::FromFileTime($_.AccountExpires)).ToString('g')
}
};$_}
如何编写代码,以便将两个标题名称更改为FirstName和LastName?
答案 0 :(得分:0)
您可以简单地获取对象并将其传递给select语句,以“别名”属性名称。
$yourObject | Select-Object -Property @{N='MyNewName1';E={$_.ExistingName1}}, @{N='MyNewName2';E={$_.ExistingName2}}