파일 시스템에 대한 Add-Content

업데이트 날짜: 2014년 5월

적용 대상: Windows PowerShell 2.0, Windows PowerShell 3.0, Windows PowerShell 4.0

내용(예: 단어 또는 데이터)을 파일에 추가합니다.

구문

Add-Content [-Encoding {<Unknown> | <String> | <Unicode> | <Byte> | <BigEndianUnicode> | <UTF8> | <UTF7> | <UTF32> | <Ascii> | <Default> | <Oem>}] [-Force] [-Stream <string>] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]

설명

파일 시스템 드라이브에서 Add-Content cmdlet은 지정한 내용을 파일의 끝에 추가합니다. 이 cmdlet을 폴더에는 사용할 수 없습니다.

참고: 이 사용자 지정 cmdlet 도움말 파일은 파일 시스템 드라이브에서 Add-Content cmdlet이 작동하는 방식에 대해 설명합니다. 모든 드라이브의 Add-Content cmdlet에 대한 자세한 내용을 보려면 "Get-HelpAdd-Content -Path $null"을 입력하거나 Add-Content(https://go.microsoft.com/fwlink/?LinkID=113278)(영문)를 참조하세요.

매개 변수

-Encoding <FileSystemCmdletProviderEncoding>

파일 인코딩을 지정합니다. 기본값은 ASCII입니다.

유효한 값은

-- ASCII: ASCII(7비트) 문자 집합에 대한 인코딩을 사용합니다.

-- BigEndianUnicode: big-endian 바이트 순서를 사용하여 UTF-16 형식으로 인코딩합니다.

-- Byte: 문자 집합을 일련의 바이트로 인코딩합니다.

-- String: 문자열에 대한 인코딩 유형을 사용합니다.

-- Unicode: Little-Endian 바이트 순서를 사용하여 UTF-16 형식으로 인코딩합니다.

-- UTF7: UTF-7 형식으로 인코딩합니다.

-- UTF8: UTF-8 형식으로 인코딩합니다.

-- Unknown: 인코딩 유형을 알 수 없거나 잘못되었습니다. 데이터가 Binary로 처리될 수 있습니다.

인코딩은 파일 시스템 공급자가 Add-Content cmdlet에 추가하는 동적 매개 변수입니다. 이 매개 변수는 파일 시스템 드라이브에만 작동합니다.

필수 여부

false

위치

명명됨

기본값

ASCII

파이프라인 입력 적용 여부

false

와일드카드 문자 허용 여부

false

-Force

파일이 읽기 전용인 경우에도 내용을 추가합니다. 이 매개 변수가 없으면 읽기 전용 파일은 영향을 받지 않습니다.

필수 여부

false

위치

명명됨

기본값

False

파이프라인 입력 적용 여부

false

와일드카드 문자 허용 여부

false

-Stream <string>

지정된 대체 데이터 스트림에 내용을 추가합니다. 스트림이 아직 존재하지 않는 경우 Add-Content가 만듭니다. 스트림 이름을 입력합니다. 와일드카드는 지원되지 않습니다.

스트림은 파일 시스템 공급자가 Add-Content cmdlet에 추가하는 동적 매개 변수입니다. 이 매개 변수는 파일 시스템 드라이브에만 작동합니다.

이 매개 변수는 Windows PowerShell 3.0에서 도입되었습니다.

필수 여부

false

위치

명명됨

기본값

파이프라인 입력 적용 여부

false

와일드카드 문자 허용 여부

false

-Confirm

명령을 실행하기 전에 확인을 요청하는 메시지가 표시됩니다.

필수 여부

false

위치

명명됨

기본값

파이프라인 입력 적용 여부

false

와일드카드 문자 허용 여부

false

-WhatIf

명령을 실제로 실행하지 않으면서 명령을 실행할 경우 어떻게 되는지 설명해 보세요.

필수 여부

false

위치

명명됨

기본값

파이프라인 입력 적용 여부

false

와일드카드 문자 허용 여부

false

-UseTransaction

활성 트랜잭션에 명령을 포함합니다. 이 매개 변수는 트랜잭션이 진행 중일 경우에만 유효합니다. 자세한 내용은 about_Transactions를 참조하세요.

필수 여부

false

위치

명명됨

기본값

파이프라인 입력 적용 여부

false

와일드카드 문자 허용 여부

false

<CommonParameters>

이 cmdlet은 일반 매개 변수 -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, -OutVariable, -Verbose, -WarningAction 및 -WarningVariable을 지원합니다. 자세한 내용은 about_CommonParameters를 참조하세요.

입력 및 출력

입력 유형은 cmdlet에 파이프할 수 있는 개체의 유형입니다. 반환 유형은 cmdlet에서 반환되는 개체의 유형입니다.

입력

Sytem.Object[], System.String[], System.Management.Automation.PSCredential

값(개체), 경로 또는 자격 증명 개체를 Add-Contnet에 파이프할 수 있습니다.

출력

없음 또는 System.String

Passthru 매개 변수를 사용할 경우 Add-Content는 내용을 나타내는 System.String 개체를 생성합니다. 그러지 않으면 이 cmdlet에서 출력이 생성되지 않습니다.

예제 1

C:\PS>Add-Content -Path *.txt -Exclude help* -Value "END"

Description
-----------
This command adds "END" to all text files in the current directory, except for those with file names that begin with "help."





예제 2

C:\PS>Add-Content -Path file1.log, file2.log -Value (get-date) -PassThru

Description
-----------
This command adds the date to the end of the File1.log and File2.log files and then displays the date at the command line. 

The command uses the Get-Date cmdlet to get the date, and it uses the Value parameter to pass the date to Add-Content. The PassThru parameter sends the added content through the pipeline. Because there is no other cmdlet to receive the passed content, it is displayed at the command line.





예제 3

C:\PS>Add-Content -Path monthly.txt -Value (Get-Content c:\rec1\weekly.txt)

Description
-----------
This command adds the contents of the Weekly.txt file to the end of the Monthly.txt file. It uses the Get-Content cmdlet to get the contents of the Weekly.txt file, and it uses the Value parameter to pass the content of weekly.txt to Add-Content. The parentheses ensure that the Get-Content command is complete before the Add-Content command begins.

You can also copy the content of Weekly.txt to a variable, such as $w, and then use the Value parameter to pass the variable to Add-Content. In that case, the command would be "add-content -path monthly.txt -value $w".





예제 4

C:\PS>Add-Content -Value (Get-Content test.log) -Path C:\tests\test134\logs\test134.log

Description
-----------
This command creates a new directory and file and copies the content of an existing file to the newly created file.

This command uses the Add-Content cmdlet to add the content. The value of the Value parameter is a Get-Content command that gets content from an existing file, Test.log. 

The value of the path parameter is a path that does not exist when the command runs. In this example, only the C:\Tests directories exist. The command creates the remaining directories and the Test134.log file.

The Force parameter is not required for this command. Add-Content creates directories to complete a path even without the Force parameter.





예제 5

C:\PS>Get-Content test.xml | Add-Content final.xml -Force -Encoding UTF8

Description
-----------
This command appends the contents of the final.xml file to the contents of the test.xml file. 

The command uses the Force parameter so that the command is successful even if the Final.xml file is read-only. It uses the Encoding parameter to specify an encoding of UTF-8.





See Also

Concepts

파일 시스템 공급자

Other Resources

Clear-Content
Get-Content
Get-ChildItem
Get-Content
Get-Item
Remove-Item
Set-Content
Test-Path