diff --git a/qa/os/src/test/java/org/elasticsearch/packaging/util/Shell.java b/qa/os/src/test/java/org/elasticsearch/packaging/util/Shell.java index 18988a7310fb4..95141aae17359 100644 --- a/qa/os/src/test/java/org/elasticsearch/packaging/util/Shell.java +++ b/qa/os/src/test/java/org/elasticsearch/packaging/util/Shell.java @@ -88,9 +88,13 @@ public void chown(Path path) throws Exception { Platforms.onLinux(() -> run("chown -R elasticsearch:elasticsearch " + path)); Platforms.onWindows(() -> run( "$account = New-Object System.Security.Principal.NTAccount '" + System.getenv("username") + "'; " + - "$tempConf = Get-ChildItem '" + path + "' -Recurse; " + - "$tempConf += Get-Item '" + path + "'; " + - "$tempConf | ForEach-Object { " + + "$pathInfo = Get-Item '" + path + "'; " + + "$toChown = @(); " + + "if ($pathInfo.PSIsContainer) { " + + " $toChown += Get-ChildItem '" + path + "' -Recurse; " + + "}" + + "$toChown += $pathInfo; " + + "$toChown | ForEach-Object { " + "$acl = Get-Acl $_.FullName; " + "$acl.SetOwner($account); " + "Set-Acl $_.FullName $acl " +