需要powershell命令来检查文件是否存在于文件存储中而不会出错
Need powerhsell command to check a file exist or not in file storage without error
$Context = (Get-AzStorageAccount -ResourceGroupName "TestServices-RG" -Name "devstestsa").Context
$file=Get-AZStorageFile -ShareName "test-file-share" -Context $Context -Path "/test.json"
以上命令有效,但如果文件不存在,它会抛出错误。有什么办法可以抑制这个错误。
错误:
指定的资源不存在。 HTTP 状态代码:404 - HTTP 错误消息:指定的资源不存在。
错误代码:
|找不到资源
ErrorMessage: 指定的资源不存在。
RequestId:50521f9b-701a-0034-6a8a-fba24a000000
时间:2021 年 2 月 5 日,星期五
| 12:12:22格林威治标准时间
获取 AzStorageFile:untitled:Untitled-1:4:10
线 |
4 | $file=Get-AZStorageFile -ShareName "test-file-share" -Context …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~
|指定的资源不存在。 HTTP 状态代码:404 - HTTP 错误消息:指定的资源不存在。
错误代码:
|找不到资源
错误消息:指定的资源不存在。
您可以尝试使用以下PowerShell脚本
$account=Get-AzStorageAccount -ResourceGroupName "" -Name ""
$share=Get-AzStorageShare -Name "share2" -Context $account.Context
$share.ShareClient.GetRootDirectoryClient().GetFileClient("test.json").Exists()
$Context = (Get-AzStorageAccount -ResourceGroupName "TestServices-RG" -Name "devstestsa").Context
$file=Get-AZStorageFile -ShareName "test-file-share" -Context $Context -Path "/test.json"
以上命令有效,但如果文件不存在,它会抛出错误。有什么办法可以抑制这个错误。
错误: 指定的资源不存在。 HTTP 状态代码:404 - HTTP 错误消息:指定的资源不存在。 错误代码: |找不到资源 ErrorMessage: 指定的资源不存在。 RequestId:50521f9b-701a-0034-6a8a-fba24a000000 时间:2021 年 2 月 5 日,星期五 | 12:12:22格林威治标准时间
获取 AzStorageFile:untitled:Untitled-1:4:10 线 | 4 | $file=Get-AZStorageFile -ShareName "test-file-share" -Context … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ |指定的资源不存在。 HTTP 状态代码:404 - HTTP 错误消息:指定的资源不存在。 错误代码: |找不到资源 错误消息:指定的资源不存在。
您可以尝试使用以下PowerShell脚本
$account=Get-AzStorageAccount -ResourceGroupName "" -Name ""
$share=Get-AzStorageShare -Name "share2" -Context $account.Context
$share.ShareClient.GetRootDirectoryClient().GetFileClient("test.json").Exists()