我具有下面的脚本,该脚本需要从Azure存储容器中删除早于7天的文件,并且该文件突然停止工作:
$StorageAccountName = "#"
$StorageAccountKey = "#"
$ContainerName = "#"
$CleanupOlderThanDays = [DateTime]::UtcNow.AddDays(-7)
$FolderName = "Daily"
$Ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
Get-AzStorageBlob -Container "$ContainerName" -Context $Ctx -Prefix $FolderName/ | Where-Object { $_.LastModified.UtcDateTime -lt $CleanupOlderThanDays } |Remove-AzStorageBlob
现在失败,并出现以下错误:
PS C:\backupcopy> .\remove_files_daily.ps1
WARNING: AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used in the
same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm'
cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of
your runbooks import both Az and AzureRM modules. More information can be found here:
https://aka.ms/azps-migration-guide.
Get-AzStorageBlob : The 'Get-AzStorageBlob' command was found in the module 'Az.Storage', but the module could not be
loaded. For more information, run 'Import-Module Az.Storage'.
At C:\backupcopy\remove_files_daily.ps1:8 char:1
+ Get-AzStorageBlob -Container "$ContainerName" -Context $Ctx -Prefix $ ...
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-AzStorageBlob:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
我尝试运行Uninstall-AzureRm,但出现以下错误:
PS C:\backupcopy> Uninstall-AzureRm
WARNING: Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the
same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can
use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure
Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found
here: https://aka.ms/azps-migration-guide
WARNING: AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used in the
same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm'
cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of
your runbooks import both Az and AzureRM modules. More information can be found here:
https://aka.ms/azps-migration-guide.
WARNING: AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used in the
same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm'
cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of
your runbooks import both Az and AzureRM modules. More information can be found here:
https://aka.ms/azps-migration-guide.
Uninstall-AzureRm : The 'Uninstall-AzureRm' command was found in the module 'Az.Accounts', but the module could not be
loaded. For more information, run 'Import-Module Az.Accounts'.
At line:1 char:1
+ Uninstall-AzureRm
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Uninstall-AzureRm:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
然后我尝试运行Import-Module Az.Accounts并获得了此信息:
WARNING: Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the
same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can
use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure
Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found
here: https://aka.ms/azps-migration-guide
WARNING: AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used in the
same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm'
cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of
your runbooks import both Az and AzureRM modules. More information can be found here:
https://aka.ms/azps-migration-guide.
Get-ChildItem : AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used
in the same script or runbook. If you are running PowerShell in an environment you control you can use the
'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation,
take care that none of your runbooks import both Az and AzureRM modules. More information can be found here:
https://aka.ms/azps-migration-guide.
At C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\1.6.2\Az.Accounts.psm1:39 char:5
+ Get-ChildItem "$PSScriptRoot\StartupScripts" -ErrorAction Stop | ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (AzureRM.Profile...igration-guide.:String) [Get-ChildItem], RuntimeExc
eption
+ FullyQualifiedErrorId : AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same se
ssion or used in the same script or runbook. If you are running PowerShell in an environment you control you can u
se the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Aut
omation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found he
re: https://aka.ms/azps-migration-guide.,Microsoft.PowerShell.Commands.GetChildItemCommand
WARNING: AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used in the
same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm'
cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of
your runbooks import both Az and AzureRM modules. More information can be found here:
https://aka.ms/azps-migration-guide.
Import-Module : AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used
in the same script or runbook. If you are running PowerShell in an environment you control you can use the
'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation,
take care that none of your runbooks import both Az and AzureRM modules. More information can be found here:
https://aka.ms/azps-migration-guide.
At line:1 char:1
+ Import-Module Az.Accounts
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (AzureRM.Profile...igration-guide.:String) [Import-Module], RuntimeExc
eption
+ FullyQualifiedErrorId : AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same se
ssion or used in the same script or runbook. If you are running PowerShell in an environment you control you can u
se the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Aut
omation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found he
re: https://aka.ms/azps-migration-guide.,Microsoft.PowerShell.Commands.ImportModuleCommand
有人知道我需要做些什么才能使它正常工作吗?我正在跑步
Major Minor Build Revision
----- ----- ----- --------
5 1 14409 1005
您无法将Az
和AzureRm
命令混合在一起,如下所示更改脚本的第一行,然后在新的Powershell会话中尝试使用。