Expand an archive without file validation

Description

This example shows how you can use the Archive resource to ensure a .zip file is expanded to a specific directory.

With Ensure set to Present, the Path set to C:\ExampleArchivePath\Archive.zip, and the Destination set to C:\ExampleDestinationPath\Destination, the resource expands the contents of Archive.zip to the Destination folder if they're not already there.

Without the Validate or Checksum properties set, the resource doesn't verify the expanded contents with the files in Archive.zip, only that they exist. The expanded content in the Destination folder may not match the contents in Archive.zip.

With Invoke-DscResource

This script shows how you can use the Archive resource with the Invoke-DscResource cmdlet to ensure Archive.zip is expanded to the Destination folder.

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

With a Configuration

This snippet shows how you can define a Configuration with an Archive resource block to ensure Archive.zip is expanded to the Destination folder.

Configuration ExpandArchiveNoValidation {
    Import-DscResource -ModuleName 'PSDscResources'

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