파일 시스템용 Set-Content

업데이트 날짜: 2014년 10월

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

파일의 내용을 사용자가 지정한 내용으로 바꿉니다.

구문

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

설명

파일 시스템 드라이브에서 Set-Content cmdlet은 하나 이상의 파일 내용을 지정한 내용으로 덮어쓰거나 바꿉니다. 이 cmdlet을 폴더에는 사용할 수 없습니다.

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

매개 변수

-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로 처리될 수 있습니다.

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

필수 여부

false

위치

명명됨

기본값

ASCII

파이프라인 입력 적용 여부

false

와일드카드 문자 허용 여부

false

-Force

파일이 읽기 전용인 경우에도 파일의 내용을 바꿉니다. 이 매개 변수가 없으면 읽기 전용 파일은 변경되지 않습니다.

필수 여부

false

위치

명명됨

기본값

파이프라인 입력 적용 여부

false

와일드카드 문자 허용 여부

false

-Stream <string>

지정된 대체 데이터 스트림의 내용을 만들거나 바꿉니다. 스트림이 아직 없는 경우 Set-Content에서 만듭니다. 스트림 이름을 입력합니다. 와일드카드는 지원되지 않습니다.

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

Set-Content cmdlet을 사용하여 Zone.Identifier 대체 데이터 스트림의 내용은 변경할 수 있습니다. 하지만 인터넷에서 다운로드한 파일을 차단하는 보안 검사를 제거하는 것은 권장되는 방법이 아닙니다. 다운로드된 파일이 안전한지 확인하려면 Unblock-File 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에서 반환되는 개체의 유형입니다.

입력

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

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

출력

없음 또는 System.String

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

예제 1

C:\PS>Set-Content -Path C:\Test1\test*.txt -Value "Hello, World"

Description
-----------
This command replaces the contents of all files in the Test1 directory that have names beginning with "test" with "Hello, World". This example shows how to specify content by typing it in the command.





예제 2

C:\PS>Get-Date | Set-Content C:\Test1\date.csv

Description
-----------
This command creates a comma-separated variable-length (csv) file that contains only the current date and time. It uses the Get-Date cmdlet to get the current system date and time. The pipeline operator passes the result to Set-Content, which creates the file and writes the content.

If the Test1 directory does not exist, the command fails, but if the file does not exist, the command will create it.





예제 3

C:\PS>Get-Content Notice.txt | ForEach-Object {$_ -replace "Warning", "Caution"} | Set-Content Notice.txt

Description
-----------
This command replaces all instances of "Warning" with "Caution" in the Notice.txt file. 

It uses the Get-Content cmdlet to get the content of Notice.txt. The pipeline operator sends the results to the ForEach-Object cmdlet, which applies the expression to each line of content in Get-Content. The expression uses the "$_" symbol to refer to the current item and the Replace parameter to specify the text to be replaced. 

Another pipeline operator sends the changed content to Set-Content which replaces the text in Notice.txt with the new content.

The parentheses around the Get-Content command ensure that the Get operation is complete before the Set operation begins. Without them, the command will fail because the two functions will be trying to access the same file.





예제 4

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

Description
-----------
This command replaces the contents of the final.xml file with 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 dynamic 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