Remove an archive without file validation

Description

This example shows how you can use the Archive resource to ensure no contents of a .zip file are expanded to a specific directory.

With Ensure set to Absent, the Path set to C:\ExampleArchivePath\Archive.zip. and the Destination set to C:\ExampleDestinationPath\Destination, the resource removes the contents of Archive.zip from the Destination folder if they exist.

Without Validate or Checksum set, the resource removes any files in the Destination folder that exist in Archive.zip.

With Invoke-DscResource

This script shows how you can use the Archive resource with the Invoke-DscResource cmdlet to ensure no contents in Archive.zip exist in the Destination folder.

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

With a Configuration

This snippet shows how you can define a Configuration with an Archive resource block to ensure no contents in Archive.zip exist in the Destination folder.

Configuration RemoveArchiveNoValidation {
    Import-DscResource -ModuleName 'PSDscResources'

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