Windows: Get rid of Set-Attr in remaining modules (#23525)
Only a few more modules were using Set-Attr on the $result object rather than using a normal hashtable. This PR changes the PSObject to a hashtable and gets rid of Set-Attr.
This commit is contained in:
parent
94bd647bc0
commit
246c84b92a
7 changed files with 37 additions and 31 deletions
|
@ -214,8 +214,9 @@ Function SetPrivilegeTokens() {
|
||||||
|
|
||||||
$params = Parse-Args $args;
|
$params = Parse-Args $args;
|
||||||
|
|
||||||
$result = New-Object PSObject;
|
$result = @{
|
||||||
Set-Attr $result "changed" $false;
|
changed = $false
|
||||||
|
}
|
||||||
|
|
||||||
$path = Get-Attr $params "path" -failifempty $true
|
$path = Get-Attr $params "path" -failifempty $true
|
||||||
$user = Get-Attr $params "user" -failifempty $true
|
$user = Get-Attr $params "user" -failifempty $true
|
||||||
|
@ -314,7 +315,7 @@ Try {
|
||||||
Try {
|
Try {
|
||||||
$objACL.AddAccessRule($objACE)
|
$objACL.AddAccessRule($objACE)
|
||||||
Set-ACL $path $objACL
|
Set-ACL $path $objACL
|
||||||
Set-Attr $result "changed" $true;
|
$result.changed = $true
|
||||||
}
|
}
|
||||||
Catch {
|
Catch {
|
||||||
Fail-Json $result "an exception occurred when adding the specified rule - $($_.Exception.Message)"
|
Fail-Json $result "an exception occurred when adding the specified rule - $($_.Exception.Message)"
|
||||||
|
@ -324,7 +325,7 @@ Try {
|
||||||
Try {
|
Try {
|
||||||
$objACL.RemoveAccessRule($objACE)
|
$objACL.RemoveAccessRule($objACE)
|
||||||
Set-ACL $path $objACL
|
Set-ACL $path $objACL
|
||||||
Set-Attr $result "changed" $true;
|
$result.changed = $true
|
||||||
}
|
}
|
||||||
Catch {
|
Catch {
|
||||||
Fail-Json $result "an exception occurred when removing the specified rule - $($_.Exception.Message)"
|
Fail-Json $result "an exception occurred when removing the specified rule - $($_.Exception.Message)"
|
||||||
|
|
|
@ -22,8 +22,9 @@
|
||||||
|
|
||||||
$params = Parse-Args $args;
|
$params = Parse-Args $args;
|
||||||
|
|
||||||
$result = New-Object PSObject;
|
$result = @{
|
||||||
Set-Attr $result "changed" $false;
|
changed = $false
|
||||||
|
}
|
||||||
|
|
||||||
$path = Get-Attr $params "path" -failifempty $true
|
$path = Get-Attr $params "path" -failifempty $true
|
||||||
$state = Get-Attr $params "state" "absent" -validateSet "present","absent" -resultobj $result
|
$state = Get-Attr $params "state" "absent" -validateSet "present","absent" -resultobj $result
|
||||||
|
@ -66,7 +67,7 @@ Try {
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-ACL $path $objACL
|
Set-ACL $path $objACL
|
||||||
Set-Attr $result "changed" $true;
|
$result.changed = $true
|
||||||
}
|
}
|
||||||
Elseif (($state -eq "absent") -And $inheritanceEnabled) {
|
Elseif (($state -eq "absent") -And $inheritanceEnabled) {
|
||||||
If ($reorganize) {
|
If ($reorganize) {
|
||||||
|
@ -76,7 +77,7 @@ Try {
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-ACL $path $objACL
|
Set-ACL $path $objACL
|
||||||
Set-Attr $result "changed" $true;
|
$result.changed = $true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Catch {
|
Catch {
|
||||||
|
|
|
@ -22,8 +22,10 @@ $ErrorActionPreference = "Stop"
|
||||||
# POWERSHELL_COMMON
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
$params = Parse-Args $args;
|
$params = Parse-Args $args;
|
||||||
$result = New-Object PSObject;
|
|
||||||
Set-Attr $result "changed" $false;
|
$result = @{
|
||||||
|
changed = $false
|
||||||
|
}
|
||||||
|
|
||||||
function Invoke-NGen
|
function Invoke-NGen
|
||||||
{
|
{
|
||||||
|
@ -42,11 +44,11 @@ function Invoke-NGen
|
||||||
if (test-path $cmd)
|
if (test-path $cmd)
|
||||||
{
|
{
|
||||||
$update = Invoke-Expression "$cmd update /force";
|
$update = Invoke-Expression "$cmd update /force";
|
||||||
Set-Attr $result "dotnet_ngen$($arity)_update_exit_code" $lastexitcode
|
$(result.dotnet_ngen$($arity)_update_exit_code) = $lastexitcode
|
||||||
Set-Attr $result "dotnet_ngen$($arity)_update_output" $update
|
$(result.dotnet_ngen$($arity)_update_output) = $update
|
||||||
$eqi = Invoke-Expression "$cmd executequeueditems";
|
$eqi = Invoke-Expression "$cmd executequeueditems";
|
||||||
Set-Attr $result "dotnet_ngen$($arity)_eqi_exit_code" $lastexitcode
|
$(result.dotnet_ngen$($arity)_eqi_exit_code) = $lastexitcode
|
||||||
Set-Attr $result "dotnet_ngen$($arity)_eqi_output" $eqi
|
$(result.dotnet_ngen$($arity)_eqi_output) = $eqi
|
||||||
|
|
||||||
$result.changed = $true
|
$result.changed = $true
|
||||||
}
|
}
|
||||||
|
|
|
@ -850,7 +850,7 @@ function Set-TargetResource
|
||||||
if($process)
|
if($process)
|
||||||
{
|
{
|
||||||
$exitCode = $process.ExitCode
|
$exitCode = $process.ExitCode
|
||||||
Set-Attr -obj $result -name "exit_code" -value $exitCode
|
$result.exit_code = $exitCode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1254,8 +1254,10 @@ namespace Source
|
||||||
|
|
||||||
|
|
||||||
$params = Parse-Args $args;
|
$params = Parse-Args $args;
|
||||||
$result = New-Object psobject;
|
|
||||||
Set-Attr $result "changed" $false;
|
$result = @{
|
||||||
|
changed = $false
|
||||||
|
}
|
||||||
|
|
||||||
$path = Get-Attr -obj $params -name path -failifempty $true -resultobj $result
|
$path = Get-Attr -obj $params -name path -failifempty $true -resultobj $result
|
||||||
$name = Get-Attr -obj $params -name name -default $path
|
$name = Get-Attr -obj $params -name name -default $path
|
||||||
|
@ -1294,7 +1296,7 @@ if (($username -ne $null) -and ($password -ne $null))
|
||||||
}
|
}
|
||||||
|
|
||||||
#Always return the name
|
#Always return the name
|
||||||
set-attr -obj $result -name "name" -value $name
|
$result.name = $name
|
||||||
|
|
||||||
$testdscresult = Test-TargetResource @dscparams
|
$testdscresult = Test-TargetResource @dscparams
|
||||||
if ($testdscresult -eq $true)
|
if ($testdscresult -eq $true)
|
||||||
|
@ -1316,12 +1318,12 @@ Else
|
||||||
#Check if DSC thinks the computer needs a reboot:
|
#Check if DSC thinks the computer needs a reboot:
|
||||||
if ((get-variable DSCMachinestatus -Scope Global -ea 0) -and ($global:DSCMachineStatus -eq 1))
|
if ((get-variable DSCMachinestatus -Scope Global -ea 0) -and ($global:DSCMachineStatus -eq 1))
|
||||||
{
|
{
|
||||||
Set-Attr $result "restart_required" $true
|
$result.restart_required = $true
|
||||||
}
|
}
|
||||||
|
|
||||||
#Set-TargetResource did its job. We can assume a change has happened
|
#Set-TargetResource did its job. We can assume a change has happened
|
||||||
Set-Attr $result "changed" $true
|
$result.changed = $true
|
||||||
Exit-Json -obj $result
|
Exit-Json -obj $result
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,7 @@ Try {
|
||||||
}
|
}
|
||||||
if ($share.CachingMode -ne $cachingMode) {
|
if ($share.CachingMode -ne $cachingMode) {
|
||||||
Set-SmbShare -Force -Name $name -CachingMode $cachingMode
|
Set-SmbShare -Force -Name $name -CachingMode $cachingMode
|
||||||
Set-Attr $result "changed" $true;
|
$result.changed = $true
|
||||||
}
|
}
|
||||||
|
|
||||||
# clean permissions that imply others
|
# clean permissions that imply others
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
|
|
||||||
$params = Parse-Args $args;
|
$params = Parse-Args $args;
|
||||||
|
|
||||||
$result = New-Object psobject @{
|
$result = @{
|
||||||
win_unzip = New-Object psobject
|
win_unzip = @{}
|
||||||
changed = $false
|
changed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ Else {
|
||||||
Fail-Json $result "PowerShellCommunityExtensions PowerShell Module (PSCX) is required for non-'.zip' compressed archive types."
|
Fail-Json $result "PowerShellCommunityExtensions PowerShell Module (PSCX) is required for non-'.zip' compressed archive types."
|
||||||
}
|
}
|
||||||
Else {
|
Else {
|
||||||
Set-Attr $result.win_unzip "pscx_status" "present"
|
$result.win_unzip.pscx_status = "present"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Import
|
# Import
|
||||||
|
@ -126,7 +126,7 @@ Else {
|
||||||
|
|
||||||
If ($rm -eq $true){
|
If ($rm -eq $true){
|
||||||
Remove-Item $src -Recurse -Force
|
Remove-Item $src -Recurse -Force
|
||||||
Set-Attr $result.win_unzip "rm" "true"
|
$result.win_unzip.rm = "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fixes a fail error message (when the task actually succeeds) for a "Convert-ToJson: The converted JSON string is in bad format"
|
# Fixes a fail error message (when the task actually succeeds) for a "Convert-ToJson: The converted JSON string is in bad format"
|
||||||
|
@ -138,8 +138,8 @@ If ($src[$src.length-1] -eq "\") {
|
||||||
If ($dest[$dest.length-1] -eq "\") {
|
If ($dest[$dest.length-1] -eq "\") {
|
||||||
$dest = $dest.Substring(0, $dest.length-1)
|
$dest = $dest.Substring(0, $dest.length-1)
|
||||||
}
|
}
|
||||||
Set-Attr $result.win_unzip "src" $src.toString()
|
$result.win_unzip.src = $src.toString()
|
||||||
Set-Attr $result.win_unzip "dest" $dest.toString()
|
$result.win_unzip.dest = $dest.toString()
|
||||||
Set-Attr $result.win_unzip "recurse" $recurse.toString()
|
$result.win_unzip.recurse = $recurse.toString()
|
||||||
|
|
||||||
Exit-Json $result
|
Exit-Json $result
|
||||||
|
|
|
@ -67,8 +67,8 @@ Function Test-IsInstalledFromWebPI
|
||||||
|
|
||||||
if ($LastExitCode -ne 0)
|
if ($LastExitCode -ne 0)
|
||||||
{
|
{
|
||||||
Set-Attr $result "webpicmd_error_cmd" $cmd
|
$result.webpicmd_error_cmd = $cmd
|
||||||
Set-Attr $result "webpicmd_error_log" "$results"
|
$result.webpicmd_error_log = "$results"
|
||||||
|
|
||||||
Throw "Error checking installation status for $package"
|
Throw "Error checking installation status for $package"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue