基本上,我想创建一个pscustomobject来纠正导出ADObject数据时的标头。我不确定是否可以将foreach传递到我拥有的代码中,或者确切地走哪条路。到目前为止,我拥有的当前代码确实可以导出到csv,但格式不符合我的要求。 我注意到我当前拥有的foreach只看到数组中的元素,而没有提取元素中的实际数据。
已经尝试创建pscustomobject,但未输出实际数据。它只是创建标题。
$ou_Array = $pOU, $lou, $fOU, $vOU, $cOU, $aOU, $auOu
$date = (Get-Date).AddDays(-14)
$get_Data =
(Get-ADObject -Filter "created -lt '$date'" -SearchBase $ou_Array[0]),
(Get-ADObject -Filter "created -lt '$date'" -SearchBase $ou_Array[1]),
(Get-ADObject -Filter "created -lt '$date'" -SearchBase $ou_Array[2]),
(Get-ADObject -Filter "created -lt '$date'" -SearchBase $ou_Array[3]),
(Get-ADObject -Filter "created -lt '$date'" -SearchBase $ou_Array[4]),
(Get-ADObject -Filter "created -lt '$date'" -SearchBase $ou_Array[5]),
(Get-ADObject -Filter "created -lt '$date'" -SearchBase $ou_Array[6])
$Results = foreach ($item in $get_Data) {
$DN = $get_Data.Context.PostContext | Where-Object {$_ -match
"DistinguishedName"}
$Name = $get_Data.Context.PostContext | Where-Object {$_ -match 'Name'}
$OC = $get_Data.Context.PostContext |
Where-Object {$_ -match 'ObjectClass'}
[pscustomobject]@{
'DN' = $DN
'Computer Name' = $Name
'Object Class' = $OC
}
}
$Results | Out-File -FilePath "C:\Users\$env:UserName\Desktop\results1.csv"
预期结果将与数据一起更正标题。实际结果是已更正的标题,但没有数据。
答案 0 :(得分:0)
您应该使用var express = require('express');
var cors = require('cors');
var bodyParser = require('body-parser');
var port = process.env.PORT || 4000;
var auth = require(/*path to Auth middleware*/);
var app = express();
app.use(bodyParser.json({ type: 'application/json' }));
app.options('*', cors());
app.use(cors());
app.use('/auth', auth);
process
.on('unhandledRejection', (reason, p) => {
console.error(reason, 'Unhandled Rejection at Promise', p);
})
.on('uncaughtException', err => {
console.error(err, 'Uncaught Exception thrown');
process.exit(1);
});
app.listen(port, function () {
console.log('RESTful API server started on: ' + port);
});
而不是Export-CSV
。