1
我有一个PowerShell功能,完全删除一个目录。我已经建立了它按(在那里与一些额外的跟踪)推荐的PowerShell作为这样PowerShell删除项目文件夹失败时只有当通过Ansible运行
function DeleteFolderAndContents()
{
param(
[Parameter(Mandatory=$true, Position=1)] [string] $folder_path
)
Get-ChildItem -Path "$folder_path" -Recurse -Force | Remove-Item -Force -Recurse
Write-Host "Deleted all files in directory. Will attempt to delete directory next"
Start-Sleep 3
Write-Host "Slept for 3 seconds. Now trying to remove folder"
Remove-Item "$folder_path" -Force
Write-Host "DeleteFolderAndContents worked seemingly without error"
while (Test-Path "$folder_path") { Start-Sleep 10 }
}
如果我在PowerShell中运行它CMDLINE它的工作原理没有问题。当Ansible尝试运行相同的脚本(通过脚本任务)时,Get-ChildItem部分工作,删除所有文件夹内容,但Remove-Item无法完全消除该目录。
我收到以下错误消息
System.Management.Automation.PSArgumentException:
An object at the specified path C:\\bblabla\\blabla\\blabla\\A.C.S.Api does not exist.
at Microsoft.PowerShell.Commands.FileSystemProvider.NormalizeThePath(String basepath, Stack`1 tokenizedPathStack),
at Microsoft.PowerShell.Commands.FileSystemProvider.NormalizeRelativePathHelper(String path, String basePath)
我不知道为什么会发生这种事。我很确定它是一个Ansible问题,但不明白如何可能,我不知道该怎么办
你懂了@techraf – Mark