February 2019
Intermediate to advanced
626 pages
15h 51m
English
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 ...
Read now
Unlock full access