【发布时间】:2015-04-09 13:16:07
【问题描述】:
我在 Azure Runbook 中有以下代码:
$pathToDownloadedBlob = 'C:\depId-20150904032522\SevenZipSharp.dll'
if ((Test-Path $pathToDownloadedBlob) -eq $true)
{
try
{
Remove-Item -Path $pathToDownloadedBlob
}
catch
{
write-error "Could not delete $pathToDownloadedBlob. - $($error[0])"
exit
}
}
当我使用Remove-Item 时出现此错误:
4/7/2015 2:14:14 PM, Error: Remove-Item : The converted JSON string is in bad format.
At DavidTest:45 char:45
+
+ CategoryInfo : InvalidOperation: (System.Unauthor... Boolean force):ErrorRecord) [Remove-Item],
InvalidOperationException
+ FullyQualifiedErrorId : JsonStringInBadFormat,Microsoft.PowerShell.Commands.RemoveItemCommand
当我改用 [System.IO.File]::Delete($using:path) 时,我收到此错误:
4/7/2015 2:22:48 PM, Error: Exception calling "Delete" with "1" argument(s): "Access to the path 'C:\Deployment\SevenZipSharp.dll' is denied."
At DavidTest:46 char:46
+
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : UnauthorizedAccessException
我知道我没有删除文件的权限。
但是,当我使用Remove-Item 时,为什么它会抱怨JSON 字符串?
编辑: 请注意,这只发生在 Azure 自动化中。但是,我并不能真正在本地的 Powershell ISE 中复制它,因为我有权删除要删除的文件。
更新:我刚刚意识到这仅发生在 .dll 文件中。如果我尝试删除 .7z 文件,它可以正常工作。
【问题讨论】:
标签: powershell azure azure-automation powershell-workflow