다음을 통해 공유


파일 유효성 검사 없이 보관 파일 확장

설명

이 예제에서는 리소스를 Archive 사용하여 파일이 특정 디렉터리로 .zip 확장되도록 하는 방법을 보여줍니다.

확인이 설정Present되고 경로가 설정C:\ExampleArchivePath\Archive.zip되고 대상이 대상으로 C:\ExampleDestinationPath\Destination설정되면 리소스는 폴더의 Archive.zip 내용을 아직 없는 경우 폴더로 Destination 확장합니다.

유효성 검사 또는 체크섬 속성이 설정되지 않은 경우 리소스는 파일이 Archive.zip있는 확장된 내용만 확인하지 않습니다. 폴더의 확장된 콘텐츠가 Destination .의 내용과 Archive.zip일치하지 않을 수 있습니다.

Invoke-DscResource

이 스크립트는 cmdlet과 함께 리소스를 ArchiveInvoke-DscResource 사용하여 폴더로 확장되도록 하는 Archive.zipDestination 방법을 보여줍니다.

[CmdletBinding()]
param()

begin {
    $SharedParameters = @{
        Name       = 'Archive'
        ModuleName = 'PSDscResource'
        Properties = @{
            Path        = 'C:\ExampleArchivePath\Archive.zip'
            Destination = 'C:\ExampleDestinationPath\Destination'
            Ensure      = 'Present'
        }
    }

    $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
    }
}

구성을 사용하여

이 코드 조각은 리소스 블록을 사용하여 ConfigurationArchive 정의하여 폴더로 확장 Destination 되도록 하는 Archive.zip 방법을 보여줍니다.

Configuration ExpandArchiveNoValidation {
    Import-DscResource -ModuleName 'PSDscResources'

    Node localhost {
        Archive ExampleArchive {
            Path        = 'C:\ExampleArchivePath\Archive.zip'
            Destination = 'C:\ExampleDestinationPath\Destination'
            Ensure      = 'Present'
        }
    }
}