We have found that using Test-Path in our environment fails intermitently, so much as we are directed to not use Test-Path in any of our scripts.
But AppDeployToolkitMain.ps1 is loaded with this cmdlet. I have managed to avoid too many AppDeployToolkitMain.ps1 edits but
when using Set-RegistryKey with Get-UserProfiles there is not an easy way around. PSADT makes it too easy by avoiding scripting all users of a computer.
This simple PSADT script fails:
$Profiles = Get-UserProfiles -ExcludeDefaultUser $true -ExcludeNTAccount @(name,name)
ForEach ($Profile in $Profiles) {
Set-RegistryKey -Key ‘HKEY_CURRENT_USER\Software\ABCompany’ -Name ‘Appearance’ -SID $Profile.SID -Type ‘DWord’ -Value ‘128’
}
ERROR:
Message : The parameter is incorrect.
InnerException :
~
PositionMessage : At D:_Projects\ABCompany\AppDeployToolkit\AppDeployToolkitMain.ps1:6926 char:32
+ … $null = New-Item -Path $key -ItemType ‘Registry’ -Force -ErrorAct …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Any ideas on how to get around PSADT Test-Path’s failure without re-writing AppDeployToolkitMain.ps1?
Test-Path cannot be used with Try/catch as it returns true/false and needs extra scripting to fail properly (might as well use Get-Item,Get-ItemProperty, Resolve-Path, etc.)