foreach 루프에서 $ serverName 값을 가진 "Server Names"에 대해 포함 된 스크립트에서 만들고있는 .csv 파일의 시작 부분에 열을 추가하고 싶습니다.CSV 시작에 열 추가
이렇게하면 CSV는 각 행의 시작 부분에 서버 이름과 함께 "서버 이름"을 포함하고 xml 파일에서 가져 오는 정보를 표시합니다.
가장 좋은 방법은 무엇입니까? 감사!
$localPath = "C:\Temp\MPOS"
$serverList = (Get-ADComputer -Filter "Name -like 'Q0*00*'" -SearchBase "OU=MPOS,OU=Prod,OU=POS,DC=company,DC=NET").name | Sort-Object | Out-File C:\Temp\MPOS\MPOSServers.txt
$serverNames = Get-Content $serverList
foreach ($serverName in $serverNames) {
Add-Content $logfile "Processing $serverName"
$serverCsv = $serverNames |
#Check if the server is online before doing the remote command
If (Test-Connection -ComputerName $serverName -Quiet -count 1) {
#copy config file from MPOS print to local server for processing
$configPath = "\\$($serverName)\D$\mposdevices\deviceconfig.xml"
Copy-Item $configPath $localPath
#process xml file to output data to csv file
$xml = Get-Content C:\Temp\MPOS\DeviceConfig.xml
$xmldata = [xml]$xml
$xmldata.DeviceConfig.ChildNodes | Export-Csv -Path C:\Temp\MPOS\MDATInfo.csv -NoTypeInformation -Append
} #If (Test-Connection -ComputerName $serverName -Quiet -count 1) {
} #foreach ($serverName in $serverNames) {
를 이해할 수있는 객체의 종류입니다
PSObject
을 생산뿐만 아니라 끝 부분에 불필요한 열 무리를 추가합니다. ServerName 열은 어떻게 만듭니 까? 빠른 응답에 감사드립니다! – LilithGoddess그 원인이되는 것은'*'입니다. '$ xmldata.DeviceConfig.ChildNodes'에 무엇이 있는지 확실하지 않습니다. '*'대신 특정 열을 추가하십시오. – TechSpud
Nevermind - 알아 냈습니다! :) 감사합니다 – LilithGoddess