파일 유효성 검사 없이 자격 증명으로 보관 파일 확장
설명
이 예제에서는 리소스를 Archive
사용하여 선택한 계정의 특정 디렉터리로 파일이 확장되도록 하는 .zip
방법을 보여줍니다. 이렇게 하면 액세스 및 쓰기에 대한 권한 부여가 필요한 보관 및 대상의 위치를 지정할 수 있습니다.
Ensure를 설정Present
, 경로로 C:\ExampleArchivePath\Archive.zip
설정 및 대상을 설정C:\ExampleDestinationPath\Destination
하면 리소스는 폴더의 Archive.zip
내용이 아직 없는 경우 폴더로 Destination
확장합니다.
자격 증명 속성을 파일 및 Destination
폴더에 대한 권한이 Archive.zip
있는 계정으로 설정하면 리소스는 해당 계정으로 파일을 확장합니다.zip
. 계정에 두 경로에 대한 권한이 없으면 리소스가 오류를 throw합니다.
유효성 검사 또는 체크섬 속성을 설정하지 않으면 리소스는 파일이 Archive.zip
있는 확장된 콘텐츠만 확인하지 않습니다. 폴더의 확장된 콘텐츠가 Destination
.의 내용과 Archive.zip
일치하지 않을 수 있습니다.
Invoke-DscResource
이 스크립트는 cmdlet에서 Invoke-DscResource
리소스를 사용하여 Archive
파일을 읽고 쓰기 위해 Destination
지정된 계정의 자격 증명을 사용하여 폴더로 확장되도록 하는 Archive.zip
방법을 보여줍니다.
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential
)
begin {
$SharedParameters = @{
Name = 'Archive'
ModuleName = 'PSDscResource'
Properties = @{
Path = 'C:\ExampleArchivePath\Archive.zip'
Destination = 'C:\ExampleDestinationPath\Destination'
Credential = $Credential
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
}
}
구성을 사용하는 경우
이 코드 조각은 파일을 읽고 쓰기 위해 지정된 계정의 자격 증명을 사용하여 폴더로 Destination
확장되도록 Archive.zip
리소스 블록을 사용하여 정의하는 Configuration
Archive
방법을 보여줍니다.
Configuration ExpandArchiveNoValidationCredential {
param(
[Parameter(Mandatory)]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential
)
Import-DscResource -ModuleName 'PSDscResources'
Node localhost {
Archive ExampleArchive {
Path = 'C:\ExampleArchivePath\Archive.zip'
Destination = 'C:\ExampleDestinationPath\Destination'
Credential = $Credential
Ensure = 'Present'
}
}
}