Closed mvaneijken closed 3 years ago
Hi @mvaneijken, thanks for finding this out, good catch.
I tested a better alternative which removing the if statements completely and adding -ErrorAction SilentlyContinue to the New-Alias directly, this one does fill up $Error, not even in the event of unloading and loading the module back:
New-Alias -Name Add-StorageTableRow -Value Add-AzTableRow -ErrorAction SilentlyContinue
New-Alias -Name Add-AzureStorageTableRow -Value Add-AzTableRow -ErrorAction SilentlyContinue
New-Alias -Name Get-AzureStorageTableTable -Value Get-AzTableTable -ErrorAction SilentlyContinue
New-Alias -Name Get-AzureStorageTableRowAll -Value Get-AzTableRowAll -ErrorAction SilentlyContinue
New-Alias -Name Get-AzureStorageTableRowByPartitionKey -Value Get-AzTableRowByPartitionKey -ErrorAction SilentlyContinue
New-Alias -Name Get-AzureStorageTableRowByPartitionKeyRowKey -Value Get-AzTableRowByPartitionKeyRowKey -ErrorAction SilentlyContinue
New-Alias -Name Get-AzureStorageTableRowByColumnName -Value Get-AzTableRowByColumnName -ErrorAction SilentlyContinue
New-Alias -Name Get-AzureStorageTableRowByCustomFilter -Value Get-AzTableRowByCustomFilter -ErrorAction SilentlyContinue
New-Alias -Name Get-AzureStorageTableRow -Value Get-AzTableRow -ErrorAction SilentlyContinue
New-Alias -Name Update-AzureStorageTableRow -Value Update-AzTableRow -ErrorAction SilentlyContinue
New-Alias -Name Remove-AzureStorageTableRow -Value Remove-AzTableRow -ErrorAction SilentlyContinue
This is the result:
PS C:\Users\user> import-module aztable
PS C:\Users\user> $Error
PS C:\Users\user> import-module aztable
PS C:\Users\user> $error
PS C:\Users\user> Remove-Module aztable
PS C:\Users\user> get-module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 0.7.0 Az.Profile {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount...}
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest 3.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest 3.0.0.0 Microsoft.WSMan.Management {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}
Script 2.0.0 PSReadline {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler...}
PS C:\Users\user> import-module aztable
PS C:\Users\user> $error
PS C:\Users\user> get-module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 0.7.0 Az.Profile {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount...}
Manifest 2.1.0 aztable {Add-AzADGroupMember, Add-AzRmStorageContainerLegalHold, Add-AzStorageAccountNetworkRule, Disable-AzStorageDeleteRetentionPolicy...}
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest 3.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest 3.0.0.0 Microsoft.WSMan.Management {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}
Script 2.0.0 PSReadline {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler...}
If you want still want to contribute, please apply only these changes to your PR and we can go from there.
That's also a possibility indeed. The goal of this PR was to preserve the routines were built-in because they are there probably for a reason.
I'll test it and update the PR later in the next couple days.
Tested and OK:
import-module .\AzureRmStorageTable.psd1
get-module AzureRmStorageTable
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 2.1.0 AzureRmStorageTable {Add-AzADGroupMember, Add-AzRmStorageContainerLegalHold, A...
$Error
import-module .\AzureRmStorageTable.psd1
get-module AzureRmStorageTable
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 2.1.0 AzureRmStorageTable {Add-AzADGroupMember, Add-AzRmStorageContainerLegalHold, A...
$error
Remove-Module AzureRmStorageTable
get-module AzureRmStorageTable
$error
import-module .\AzureRmStorageTable.psd1 -force
get-module AzureRmStorageTable
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 2.1.0 AzureRmStorageTable {Add-AzADGroupMember, Add-AzRmStorageContainerLegalHold, A...
$Error
import-module .\AzureRmStorageTable.psd1 -force
get-module AzureRmStorageTable
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 2.1.0 AzureRmStorageTable {Add-AzADGroupMember, Add-AzRmStorageContainerLegalHold, A...
$error
Remove-Module AzureRmStorageTable
get-module AzureRmStorageTable
$Error
Thanks @mvaneijken, this is now merged.
Describe the PR Request
Import-Module AzTable
fills the$Error
variable withSystem.Management.Automation.ItemNotFoundException
exceptions like:Get-Alias : This command cannot find a matching alias because an alias with the name 'Remove-AzureStorageTableRow' does not exist.
. The error sources in fileAzureRmStorageTableCoreHelper.psm1
Although the
-ErrorAction "SilentlyContinue"
is used in that file, the error is still recorded in the$Error
variable.When using this module in Azure Automation it still fails reporting this error.
I would propose to make the following change: Replace the lines containing
If (-not (Get-Alias -Name <AliasName> -ErrorAction SilentlyContinue))
toIf (-not (Get-Alias | Where-Object Name -eq "<AliasName>" ))
Error Message
PowerShell Version
More information