파일 유효성 검사 없이 보관 파일 제거
설명
이 예제에서는 리소스를 Archive
사용하여 파일의 .zip
내용이 특정 디렉터리로 확장되지 않도록 하는 방법을 보여 줍니다.
Ensure를 설정하면 Absent
경로가 로 설정됩니다C:\ExampleArchivePath\Archive.zip
. 대상을 설정하면 C:\ExampleDestinationPath\Destination
리소스는 폴더의 Archive.zip
내용이 있는 경우 폴더에서 Destination
해당 내용을 제거합니다.
유효성 검사 또는 체크섬 집합이 없으면 리소스는 폴더에 Destination
있는 Archive.zip
모든 파일을 제거합니다.
Invoke-DscResource
이 스크립트는 cmdlet과 함께 리소스를 Archive
Invoke-DscResource
사용하여 폴더에 콘텐츠가 없도록 하는 방법을 보여 줍니다 Archive.zip
Destination
.
[CmdletBinding()]
param()
begin {
$SharedParameters = @{
Name = 'Archive'
ModuleName = 'PSDscResource'
Properties = @{
Path = 'C:\ExampleArchivePath\Archive.zip'
Destination = 'C:\ExampleDestinationPath\Destination'
Ensure = 'Absent'
}
}
$NonGetProperties = @(
'Ensure'
)
}
process {
$TestResult = Invoke-DscResource -Method Test @SharedParameters
if ($TestResult.InDesiredState) {
$QueryParameters = $SharedParameters.Clone()
foreach ($Property in $NonGetProperties) {
$QueryParameters.Properties.Remove($Property)
}
Invoke-DscResource -Method Get @QueryParameters
} else {
Invoke-DscResource -Method Set @SharedParameters
}
}
구성을 사용하여
이 코드 조각에서는 리소스 블록을 사용하여 Configuration
Archive
정의하여 폴더에 Archive.zip
Destination
콘텐츠가 없도록 하는 방법을 보여 줍니다.
Configuration RemoveArchiveNoValidation {
Import-DscResource -ModuleName 'PSDscResources'
Node localhost {
Archive ExampleArchive {
Path = 'C:\ExampleArchivePath\Archive.zip'
Destination = 'C:\ExampleDestinationPath\Destination'
Ensure = 'Absent'
}
}
}
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.