2012-05-29 2 views
1

우선 PowerShell과 스크립팅을 처음 접했습니다. 일반적으로 양해 해 주셔서 대단히 감사합니다.Powershell : 사용자 입력의 에코를 여러 텍스트 파일로 리디렉션

사용자가 입력 한 값 (정규화 된 도메인 이름)을 "servers.txt"라는 문서에 쓰는 스크립트가 있습니다. 대신 다른 위치에있는 "servers.txt"사본을 여러 개 추가하고 싶습니다. 불행하게도 하나의 "servers.txt"파일 만 갖는 것은 옵션이 아닙니다. 다양한 "servers.txt"파일에 액세스하는 다양한 스크립트는 때로는 고유 한 데이터가있는 독립적 인 파일을 필요로하지만, 몇 달에 한 번씩 (또는 적어도 일정한 항목을 포함하는 모든 이벤트)를 예약합니다.

출력 파일에 대한 get-help를 점검하고 여러 출력에 대한 참조를 보지 않았습니다. 나는 잠시 동안 인터넷 검색을 해봤지만, 많은 사람들이 내가 시도하고있는 일을하고 싶어하지 않는다 (또는 나는 그 질문을하는 진절머리 나는 일을하고있다).

# This variable exists to ensure the loop continues forever. 
$yes="y" 

#Information for the user 
ECHO "This script adds your input to every servers.txt file. You may press "VIEW" at any time to see what currently exists in a servers.txt file" 

#Loop. The script requests the FQDN or the command "exit" or "view". Exit ends the script, VIEW shows the current content of servers.txt. If an FQDN is tested for positively, it will append the user's value to servers.txt 
do { 

$a = read-host "Please Input Server FQDN here, or type EXIT to end the loop" 

#test for command to quit (exit) 
if ($a -eq "exit") 
    { 
     exit 

    } 
#test for command to view contents of servers.txt 
if ($a -eq "view") 
    { 
     get-content servers.txt 

    } 
#if not exit or view, check if this is a proper FQDN 
else 
     { 

     IF ($a -match "^[a-zA-Z0-9]+([a-zA-Z0-9\-\.]+)?\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU|internal)$") 

#If test for FQDN is positive append value to servers.txt 
      { 
       echo $a | out-file "servers.txt" -append 
      } 
#If test fails, return error 

     ELSE 
      {echo "Entry is Invalid"} 


     } 



} 

#continue looping forever because YES always is equal to Y 

while ($yes -eq "y") 

답변

3

시도-내용을 추가합니다 : 여기

는 스크립트입니다

"TESTING" | Add-Content -Path "C:\temp\test1.txt","C:\temp\test2.txt" 
+0

대단히 감사합니다! – Ricky

관련 문제