aws / aws-tools-for-powershell

The AWS Tools for PowerShell lets developers and administrators manage their AWS services from the PowerShell scripting environment.
Apache License 2.0
243 stars 81 forks source link

Install-AWSToolsModule results in error of Unable to find repository "AWSToolsTemp" #65

Closed sheldonhull closed 4 years ago

sheldonhull commented 5 years ago

Expected Behavior

I would like to use this cmdlet to install the required modules and upgrade as required as part of a module setup process I'm working on. I want it to proceed with installation or else bypass without error if the module already is correctly installed.

Current Behavior

AWS.Tools.Installer\Install-AWSToolsModule -Name 'AWS.Tools.SimpleSystemsManagement', 'AWS.Tools.S3' -RequiredVersion 3.3.563.1 -Confirm:$false -CleanUp -SkipUpdate  -AllowClobber

Trying to use AWS.Tools.Installer to manage the newer modules AWS.Tools.* results in an error message indicated:

PackageManagement\Unregister-PackageSource : Unable to find repository 'AWSToolsTemp'. Use Get-PSRepository to see all available repositories.
At C:\Users\$ENV:USERNAME\Documents\WindowsPowerShell\Modules\PowerShellGet\2.2.1\PSModule.psm1:12808 char:21
............
The property 'Name' cannot be found on this object. Verify that the property exists.
At C:\Users\$ENV:USERNAME\Documents\WindowsPowerShell\Modules\PowerShellGet\2.2.1\PSModule.psm1:11527 char:17

Your Environment

Include as many relevant details about the environment where the bug was discovered.

matteo-prosperi commented 5 years ago

Hello, could you try running the command with the -Verbose switch and attach the full output?

sheldonhull commented 4 years ago

I updated to latest and still have this error. Here's the attached info. Thanks!

VERBOSE: [Install-AWSToolsModule] ConfirmPreference=None WhatIfPreference=False VerbosePreference=Continue Force=False
VERBOSE: [Install-AWSToolsModule] Searching installed modules
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.CloudWatch.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ConfigService.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.IdentityManagement.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Installer.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Installer.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.RDS.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.S3.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.SecretsManager.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.SecurityToken.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.SimpleSystemsManagement.

VERBOSE: [Install-AWSToolsModule] Merging existing modules into the list of modules to install
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.CloudWatch.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ConfigService.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.IdentityManagement.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.RDS.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.S3.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.SecretsManager.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.SecurityToken.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.SimpleSystemsManagement.

VERBOSE: Performing the operation "Install-AWSToolsModule" on target "AWS Tools version 4.0.0.1".
VERBOSE: [Install-AWSToolsModule] Create folder for temporary repository C:\Users\{{USERNAME}}\AppData\Local\Temp\xaconrqj.tii
VERBOSE: [Install-AWSToolsModule] Registering temporary repository AWSToolsTemp
VERBOSE: [Install-AWSToolsModule] Unregistering temporary repository AWSToolsTemp

PackageManagement\Unregister-PackageSource : Unable to find repository 'AWSToolsTemp'. Use Get-PSRepository to see all available repositories.
At C:\Users\{{USERNAME}}\Documents\PowerShell\Modules\PowerShellGet\2.2.2\PSModule.psm1:12808 char:21
+  ...     $null = >>>PackageManagement\Unregister-PackageSource @PSBoundParame<<< ...        

VERBOSE: [Install-AWSToolsModule] Delete repository folder C:\Users\{{USERNAME}}\AppData\Local\Temp\xaconrqj.tii
PackageManagement\Register-PackageSource : The property 'Name' cannot be found on this object. Verify that the property exists.
At C:\Users\{{USERNAME}}\Documents\PowerShell\Modules\PowerShellGet\2.2.2\PSModule.psm1:11527 char:17
+  ...     $null = >>>PackageManagement\Register-PackageSource @PSBoundParamete<<< ...

I've confirmed I'm on PowershellGet 2.2.2 in the current session scope as well as the latest version as of today in the PSGallery.

matteo-prosperi commented 4 years ago

Thanks for sharing the verbose log.

This is the relevant part of code (with minimal simplifications) that is failing for you.

$AWSToolsTempRepoName = 'AWSToolsTemp'
$temporaryRepoDirectory = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
Write-Verbose "Create folder for temporary repository $temporaryRepoDirectory"
New-Item -ItemType Directory -Path $temporaryRepoDirectory -WhatIf:$false | Out-Null
try {
    Unregister-PSRepository -Name $AWSToolsTempRepoName -ErrorAction 'SilentlyContinue'
    Write-Output "Registering temporary repository $script:AWSToolsTempRepoName"
    Register-PSRepository -Name $AWSToolsTempRepoName -SourceLocation $temporaryRepoDirectory -ErrorAction 'Stop'
    Set-PSRepository -Name $AWSToolsTempRepoName -InstallationPolicy Trusted

    Write-Output "Do stuff..."
}
finally {
    Write-Output "Unregistering temporary repository $script:AWSToolsTempRepoName"
    Unregister-PSRepository -Name $AWSToolsTempRepoName -ErrorAction 'Continue'

    Write-Output "Delete repository folder $temporaryRepoDirectory"
    Remove-Item -Path $temporaryRepoDirectory -Recurse -WhatIf:$false
}

You should be able to replicate the failure by running it.

The weird thing that I can see in your log is

Create folder for temporary repository C:\Users\{{USERNAME}}\AppData\Local\Temp\xaconrqj.tii

So it looks like [System.IO.Path]::GetTempPath() is returning C:\Users\{{USERNAME}}\AppData\Local\Temp. I suppose that is not a valid path and that it probably trips PowerShellGet. Could you please validate this assumption by running

[System.IO.Path]::GetTempPath()

in your shell?

Based on https://docs.microsoft.com/en-us/dotnet/api/system.io.path.gettemppath, GetTempPath uses one of the following variables: $Env:TMP, $Env:TEMP, $Env:USERPROFILE. Could you validate whether they are correctly set?

matteo-prosperi commented 4 years ago

Hello, did you have a chance of investigating this issue further? Thanks

sheldonhull commented 4 years ago

[System.IO.Path]::GetTempPath() returns C:\Users\MyUser\AppData\Local\Temp\ correctly. My temp variable is set.

matteo-prosperi commented 4 years ago

You could try to run directly in a PowerShell session the code that appears to fail according to your log:

$AWSToolsTempRepoName = 'AWSToolsTemp'
$temporaryRepoDirectory = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
Write-Verbose "Create folder for temporary repository $temporaryRepoDirectory"
New-Item -ItemType Directory -Path $temporaryRepoDirectory -WhatIf:$false | Out-Null
try {
    Unregister-PSRepository -Name $AWSToolsTempRepoName -ErrorAction 'SilentlyContinue'
    Write-Output "Registering temporary repository $script:AWSToolsTempRepoName"
    Register-PSRepository -Name $AWSToolsTempRepoName -SourceLocation $temporaryRepoDirectory -ErrorAction 'Stop'
    Set-PSRepository -Name $AWSToolsTempRepoName -InstallationPolicy Trusted

    Write-Output "Do stuff..."
}
finally {
    Write-Output "Unregistering temporary repository $script:AWSToolsTempRepoName"
    Unregister-PSRepository -Name $AWSToolsTempRepoName -ErrorAction 'Continue'

    Write-Output "Delete repository folder $temporaryRepoDirectory"
    Remove-Item -Path $temporaryRepoDirectory -Recurse -WhatIf:$false
}
sheldonhull commented 4 years ago

Ran manually and obtained this error.

Registering temporary repository AWSToolsTemp
Unregistering temporary repository AWSToolsTemp
PackageManagement\Unregister-PackageSource : Unable to find repository 'AWSToolsTemp'. Use Get-PSRepository to see all available repositories.
At C:\Users\USERNAME\Documents\PowerShell\Modules\PowerShellGet\2.2.2\PSModule.psm1:12808 char:21
+  ...     $null = >>>PackageManagement\Unregister-PackageSource @PSBoundParame<<< ...

Delete repository folder C:\Users\USERNAME\AppData\Local\Temp\rbjxzpbz.g30
The property 'Name' cannot be found on this object. Verify that the property exists.
At C:\Users\USERNAME\Documents\PowerShell\Modules\PowerShellGet\2.2.2\PSModule.psm1:11527 char:17
+ ...     $null = PackageManagement\Register-PackageSource @PSBoundParamete ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Microsoft.PowerShel\u2026gisterPackageSource:RegisterPackageSource) [Register-PackageSource], Exception
    + FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource
matteo-prosperi commented 4 years ago

Hello, considering that you were able to reproduce an error by simply using PowerShellGet commands, I suggest opening an issue at https://github.com/PowerShell/PowerShellGet. If I read your logs correctly, this is the simplified code that is causing the error:

$temporaryRepoDirectory = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
Register-PSRepository -Name 'AWSToolsTemp' -SourceLocation $temporaryRepoDirectory -ErrorAction 'Stop'

AWS.Tools.Installer relies on PowerShellGet (the module providing Install-Module and Register-PSRepository) to perform module installations.

sheldonhull commented 4 years ago

Just a quick update that I'm still experiencing this. I'm not sure why this is happening. I've force imported PowerShellGet 2.2.3 and still get this too. In backtracking through this, I see this possible code that does a Test-Path. This would expect the path to already exist, correct?

        'DestinationPath' {
            $returnValue = Test-Path -Path $Value

            if ($returnValue -eq $false) {
                $errorMessage = $script:localizedData.PathDoesNotExist -f $Value
                New-InvalidArgumentException -ArgumentName $Type -Message $errorMessage
            }
        }

I can open an item on their issues board, but wanted to confirm you don't get this error in PowerShellGet 2.2.1 when the folder doesn't exist. The registery of that path and subsequent commands are expected to create it not exists, correct?

ashishdhingra commented 4 years ago

Hi @sheldonhull,

Good morning.

I was going through the issue backlog and came across this issue. Please confirm if this is still an issue. I was able to execute the command mentioned in the issue successfully:

Install-AWSToolsModule -Name 'AWS.Tools.SimpleSystemsManagement', 'AWS.Tools.S3' -RequiredVersion 3.3.563.1 -Confirm:$false -CleanUp -SkipUpdate  -AllowClobber                       
Installing module AWS.Tools.S3 version 3.3.563.1
Installing module AWS.Tools.SimpleSystemsManagement version 3.3.563.1                                               Uninstalling AWS.Tools version 4.1.0.0                                                                              Uninstalling module AWS.Tools.CloudWatch                                                                            Uninstalling module AWS.Tools.CloudWatchLogs                                                                        Uninstalling module AWS.Tools.CodeCommit                                                                            Uninstalling module AWS.Tools.CognitoIdentityProvider                                                               
Uninstalling module AWS.Tools.EC2
Uninstalling module AWS.Tools.ElasticMapReduce
Uninstalling module AWS.Tools.Imagebuilder
Uninstalling module AWS.Tools.S3
Uninstalling module AWS.Tools.Common
Uninstalling AWS.Tools version 4.1.1.0
Uninstalling module AWS.Tools.CloudWatch
Uninstalling module AWS.Tools.CloudWatchLogs
Uninstalling module AWS.Tools.CodeCommit
Uninstalling module AWS.Tools.CognitoIdentityProvider
Uninstalling module AWS.Tools.EC2
Uninstalling module AWS.Tools.ElasticMapReduce
Uninstalling module AWS.Tools.Glacier
Uninstalling module AWS.Tools.Imagebuilder
Uninstalling module AWS.Tools.S3
Uninstalling module AWS.Tools.SimpleNotificationService
Uninstalling module AWS.Tools.SQS
Uninstalling module AWS.Tools.Common

Thanks, Ashish

sheldonhull commented 4 years ago

I never resolved it. I'm now on macOS and have never had this issue so I'd go ahead and close it if not able to reproduce. If I come across this in the future I'll be sure to update this or open and linked issue.

Thanks for the follow up 🤟

ashishdhingra commented 4 years ago

@sheldonhull Thanks for the update. Based on your input I'm closing this issue. Feel free to open a new issue, adding reference to this one, in case you encounter the problem in future.

mwoffenden commented 3 years ago

The problem stlll exists on Windows in January 2021. BIG problem. Any chance on a fix?

This is on a brand new Windows VM. Nothing else but Windows installed.

PS C:\Windows\system32> Install-AWSToolsModule AWS.Tools.EC2 -CleanUp Installing module AWS.Tools.EC2 version 4.1.6.0 Where-Object : The property 'Version' cannot be found on this object. Verify that the property exists. At C:\Program Files\WindowsPowerShell\Modules\AWS.Tools.Installer\1.0.2.0\AWS.Tools.Installer.psm1:178 char:69

  • ... alledAwsToolsModules | Where-Object { $_.Version -ne $ExceptVersion }
  • 
    + CategoryInfo          : NotSpecified: (:) [Where-Object], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.Commands.WhereObjectCommand
timopuik commented 3 years ago

I concur with @mwoffenden, this issue still exists as of now. @ashishdhingra do we really need to open a new issue as the situation has not changed?

ashishdhingra commented 3 years ago

Hi @timopuik / @mwoffenden,

Please open a new issue mentioning the details in the below format. It would be helpful to specify the environment, PowerShell version installed and exact steps for reproduction. You may link your comment to the new issue.

Expected Behavior

Current Behavior

Possible Solution

Steps to Reproduce (for bugs)

Context

Your Environment

.NET Core Info

Thanks, Ashish

starcry commented 3 years ago

can we please either reopen this issue or get a reference to an open issue? I'm having this issue too

PS C:\Windows\system32\config\systemprofile> Install-AWSToolsModule AWS.Tools.EC2,AWS.Tools.S3 -CleanUp -Force
Installing module AWS.Tools.EC2 version 4.1.8.0
Installing module AWS.Tools.S3 version 4.1.8.0
Where-Object : The property 'Version' cannot be found on this object. Verify that the property exists.
At C:\Program Files\WindowsPowerShell\Modules\AWS.Tools.Installer\1.0.2.0\AWS.Tools.Installer.psm1:178 char:69
+ ... alledAwsToolsModules | Where-Object { $_.Version -ne $ExceptVersion }
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Where-Object], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.Commands.WhereObjectCommand

PS C:\Windows\system32\config\systemprofile> Install-AWSToolsModule AWS.Tools.EC2,AWS.Tools.S3 -CleanUp -Force -Verbose
VERBOSE: [Install-AWSToolsModule] ConfirmPreference=High WhatIfPreference=False VerbosePreference=Continue Force=True Name=(AWS.Tools.EC2 AWS.Tools.S3) RequiredVersion= SkipUpdate=False CleanUp=True
VERBOSE: [Find-AWSToolsModule] ConfirmPreference=High WhatIfPreference=False VerbosePreference=Continue Name=(AWS.Tools.EC2 AWS.Tools.S3)
VERBOSE: [Find-AWSToolsModule] End
VERBOSE: [Install-AWSToolsModule] Installing AWS Tools version 4.1.8.0
VERBOSE: [Install-AWSToolsModule] Searching installed modules
VERBOSE: [Install-AWSToolsModule] Removing already installed modules from the. Final list of modules to install: (AWS.Tools.EC2 AWS.Tools.S3)
VERBOSE: [Install-AWSToolsModule] Create folder for temporary repository C:\Windows\TEMP\meb3zpzt.p4t
VERBOSE: [Install-AWSToolsModule] Registering temporary repository AWSToolsTemp
VERBOSE: [Install-AWSToolsModule] Downloading modules to temporary repository
VERBOSE: [Install-AWSToolsModule] Downloading modules (AWS.Tools.EC2 AWS.Tools.S3)
VERBOSE: [Install-AWSToolsModule] Downloading module AWS.Tools.EC2 to C:\Windows\TEMP\meb3zpzt.p4t
VERBOSE: [Install-AWSToolsModule] Downloading module AWS.Tools.S3 to C:\Windows\TEMP\meb3zpzt.p4t
VERBOSE: [Get-AWSToolsModuleDependenciesAndValidate] ConfirmPreference=None WhatIfPreference=False VerbosePreference=Continue Name=AWS.Tools.EC2 Path=C:\Windows\TEMP\meb3zpzt.p4t\AWS.Tools.EC2.4.1.8.0.nupkg
VERBOSE: [Get-AWSToolsModuleDependenciesAndValidate] Manifest signature correctly validated
VERBOSE: [Get-AWSToolsModuleDependenciesAndValidate] Found dependency AWS.Tools.Common
VERBOSE: [Get-AWSToolsModuleDependenciesAndValidate] End
VERBOSE: [Get-AWSToolsModuleDependenciesAndValidate] ConfirmPreference=None WhatIfPreference=False VerbosePreference=Continue Name=AWS.Tools.S3 Path=C:\Windows\TEMP\meb3zpzt.p4t\AWS.Tools.S3.4.1.8.0.nupkg
VERBOSE: [Get-AWSToolsModuleDependenciesAndValidate] Manifest signature correctly validated
VERBOSE: [Get-AWSToolsModuleDependenciesAndValidate] Found dependency AWS.Tools.Common
VERBOSE: [Get-AWSToolsModuleDependenciesAndValidate] End
VERBOSE: [Install-AWSToolsModule] Downloading module AWS.Tools.Common to C:\Windows\TEMP\meb3zpzt.p4t
VERBOSE: [Get-AWSToolsModuleDependenciesAndValidate] ConfirmPreference=None WhatIfPreference=False VerbosePreference=Continue Name=AWS.Tools.Common Path=C:\Windows\TEMP\meb3zpzt.p4t\AWS.Tools.Common.4.1.8.0.nupkg
VERBOSE: [Get-AWSToolsModuleDependenciesAndValidate] Manifest signature correctly validated
VERBOSE: [Get-AWSToolsModuleDependenciesAndValidate] End
VERBOSE: [Install-AWSToolsModule] Installing modules (AWS.Tools.EC2 AWS.Tools.S3)
Installing module AWS.Tools.EC2 version 4.1.8.0
Installing module AWS.Tools.S3 version 4.1.8.0
VERBOSE: [Install-AWSToolsModule] Modules install complete
VERBOSE: [Install-AWSToolsModule] Unregistering temporary repository AWSToolsTemp
VERBOSE: [Install-AWSToolsModule] Delete repository folder C:\Windows\TEMP\meb3zpzt.p4t
VERBOSE: [Uninstall-AWSToolsModule] ConfirmPreference=None WhatIfPreference=False VerbosePreference=Continue Force=False
VERBOSE: [Uninstall-AWSToolsModule] Searching installed modules
Where-Object : The property 'Version' cannot be found on this object. Verify that the property exists.
At C:\Program Files\WindowsPowerShell\Modules\AWS.Tools.Installer\1.0.2.0\AWS.Tools.Installer.psm1:178 char:69
+ ... alledAwsToolsModules | Where-Object { $_.Version -ne $ExceptVersion }
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Where-Object], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.Commands.WhereObjectCommand
ashishdhingra commented 3 years ago

Opened new issue https://github.com/aws/aws-tools-for-powershell/issues/194

ashishdhingra commented 3 years ago

The problem stlll exists on Windows in January 2021. BIG problem. Any chance on a fix?

This is on a brand new Windows VM. Nothing else but Windows installed.

PS C:\Windows\system32> Install-AWSToolsModule AWS.Tools.EC2 -CleanUp Installing module AWS.Tools.EC2 version 4.1.6.0 Where-Object : The property 'Version' cannot be found on this object. Verify that the property exists. At C:\Program Files\WindowsPowerShell\Modules\AWS.Tools.Installer\1.0.2.0\AWS.Tools.Installer.psm1:178 char:69

  • ... alledAwsToolsModules | Where-Object { $_.Version -ne $ExceptVersion }
  •                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : NotSpecified: (:) [Where-Object], PropertyNotFoundException
    • FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.Commands.WhereObjectCommand

The issue is perhaps caused on AWS Windows AMI due to default PowerShell version 5.1.17763.1490 installed. Upgrading PowerShell to version 6 or later (used 7.1.2) resolves the issue. I have added comment to the new issue #194 that it should handle erroneous scenario.

ashishdhingra commented 3 years ago

Another open issue https://github.com/aws/aws-tools-for-powershell/issues/161

ashishdhingra commented 3 years ago

This should be fixed in AWS.Tools.Installer 1.0.2.1

AliakseiYermachonak commented 3 years ago

@ashishdhingra , I am facing this issue, with "Unable to find repository "AWSToolsTemp" " and I've tried different versions of the 7th powershell lots of times and it never worked properly. Is there an open ticket about it and approximate solution date?