0
아래와 같이 하나의 파일을 포맷하려고합니다.powershell에서 파일 형식을 지정하는 방법
IPAddresss HostName Result
none sinuiy01.infra.go2uti.com NotValid
none sinuid20.devtst.go2uti.com NotValid
172.21.40.204 USEM9999.essilor.res Success
172.21.40.204 webmail.nscorp.com NotValid
172.21.40.204 nsc.nscorp.com Unsuccess
172.21.40.204 bp-nsc.nscorp.com NotValid
당신은 내가 위의 결과를 얻기 위해 사용한다 whcih 기능을 제안 시겠어요 - :
IPAddresss HostName Result
none sinuiy01.infra.go2uti.com NotValid
none sinuid20.devtst.go2uti.com NotValid
172.21.40.204 USEM9999.essilor.res Success
172.21.40.204 webmail.nscorp.com NotValid
172.21.40.204 nsc.nscorp.com Unsuccess
172.21.40.204 bp-nsc.nscorp.com NotValid
하지만은 아래와 같은 결과를해야합니까? 당신이 서식 다음 문자열을 시도 할 수있는 텍스트 파일로 출력 데이터를 문자열을 사용하고 여기에
스크립트가
"IPAddresss HostName Result" | Out-File -Append D:\CEP\testlogging.txt
$lines = Get-Content myfile.txt | Where {$_ -notmatch "((^#)|(^\s+$))"}
foreach ($line in $lines) {
$fields = $line -split '\s+'
$ip = $fields[0]
for ($i = 1; $i -lt $fields.Length; $i++) {
$ESXHost = $fields[$i]
echo "Host $ESXHOST"
try
{
$currentConnection = Test-Connection $ESXHost -ErrorAction stop
if($currentConnection.Count -gt 0)
{
$hostIP = ($currentConnection)[$i].IPV4Address.IPAddressToString
echo "hostIp $hostIP"
if ($hostIP -eq $ip)
{
"$hostIP $ESXHost Success" | Format-Table -Wrap -AutoSize | Out-File -Append D:\CEP\testlogging.txt
}
else
{
"$hostIP $ESXHost Unsuccessful" | Format-Table -Wrap -AutoSize | Out-File -Append D:\CEP\testlogging.txt
}
}
}
파일의 형식은 무엇입니까? 그리고 그 데이터를 PowerShell에서 파일로 출력하고 있습니까 아니면 PowerShell에서 파일을 읽으려고합니까? 당신이 작업 한 행동 강령을 가지고 있습니까? – Richard
파일은 .txt이며 파워 쉘 스크립트에서 사용하려고합니다. Format-Table -Wrap과 같은 것 - 자동 축소 | Out-File -D : \ CEP \ testlogging.txt를 입력하십시오. – sharsour
아래의 대답을 확인하십시오 :) – Richard