Implementing Set

The Set method deals with making a change, if a change is required. Set can ordinarily assume that Test has been run, and therefore that a change is required.

As the resource allows a user to ensure a value is either present or absent, it must handle the creation and deletion of the value:

[Void] Set() {
$params = @{
Path = $this.path
Name = $this.valueName
}
if ($this.Ensure -eq 'Present') {
New-ItemProperty -Value $this.Description -Type String -Force @params
} else {
$key = Get-Item $this.Path
if ($key.GetValueNames() -contains $this.valueName) {
Remove-ItemProperty @params
}
}
}

This version of Set uses the Force parameter of New-ItemProperty to overwrite any existing values of the same name. Using Force also handles cases where the value exists but the value type is incorrect.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.150.80