diff --git a/lib/ansible/module_utils/powershell.ps1 b/lib/ansible/module_utils/powershell.ps1 index 62cf3476fe..6bf0c27734 100644 --- a/lib/ansible/module_utils/powershell.ps1 +++ b/lib/ansible/module_utils/powershell.ps1 @@ -205,6 +205,10 @@ Function Get-AnsibleParam($obj, $name, $default = $null, $resultobj = @{}, $fail if ($type -eq "path") { # Expand environment variables on path-type $value = Expand-Environment($value) + # Test if a valid path is provided + if (-not (Test-Path -IsValid $value)) { + Fail-Json -obj $resultobj -message "Get-AnsibleParam: Parameter '$name' has an invalid path '$value' specified." + } } elseif ($type -eq "str") { # Convert str types to real Powershell strings $value = $value.ToString() diff --git a/lib/ansible/modules/windows/win_shortcut.ps1 b/lib/ansible/modules/windows/win_shortcut.ps1 index 2a97bf1fef..891fcc89d8 100644 --- a/lib/ansible/modules/windows/win_shortcut.ps1 +++ b/lib/ansible/modules/windows/win_shortcut.ps1 @@ -26,7 +26,7 @@ $ErrorActionPreference = "Stop" $params = Parse-Args $args -supports_check_mode $true $check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false -$src = Get-AnsibleParam -obj $params -name "src" -type "path" +$src = Get-AnsibleParam -obj $params -name "src" $dest = Get-AnsibleParam -obj $params -name "dest" -type "path" -failifempty $true $state = Get-AnsibleParam -obj $params -name "state" -type "string" -default "present" -validateset "present","absent" $orig_args = Get-AnsibleParam -obj $params -name "args" -type "string"