Install-PSResource on module "Az" results in error "Could not find file [...] Az.ps1"
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
Steps to reproduce
Installing the Az
module using Install-PSResource
should successfully install the module, however, it results in a failure.
Install-PSResource -Name Az
However, executing the code below can be used as a workaround that successfully installs the module. The reason is unknown.
Install-PSResource -Name Az -Repository PSGallery
Expected behavior
Successful installation
Actual behavior
PS> Install-PSResource -Name Az
Install-PSResource: Unable to successfully install package 'Az': 'Could not find file '/var/folders/sx/vwrdwvmn3_q1n854bqt5p2wh0000gn/T/b4a03b2c-92cf-48d4-aca5-9ad29a05f09d/az/1.0.0.5/Az.ps1'.'
Error details
PS> Get-Error
Exception :
Type : System.Management.Automation.PSInvalidOperationException
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : Unable to successfully install package 'Az': 'Could not find file
'/var/folders/sx/vwrdwvmn3_q1n854bqt5p2wh0000gn/T/b4a03b2c-92cf-48d4-aca5-9ad29a05f09d/az/1.0.0.5/Az.ps1'.'
HResult : -2146233087
CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : InvalidOperation
Message : Unable to successfully install package 'Az': 'Could not find file
'/var/folders/sx/vwrdwvmn3_q1n854bqt5p2wh0000gn/T/b4a03b2c-92cf-48d4-aca5-9ad29a05f09d/az/1.0.0.5/Az.ps1'.'
InnerException :
Type : System.IO.FileNotFoundException
Message : Could not find file
'/var/folders/sx/vwrdwvmn3_q1n854bqt5p2wh0000gn/T/b4a03b2c-92cf-48d4-aca5-9ad29a05f09d/az/1.0.0.5/Az.ps1'.
FileName : /var/folders/sx/vwrdwvmn3_q1n854bqt5p2wh0000gn/T/b4a03b2c-92cf-48d4-aca5-9ad29a05f09d/az/1.0.0.5/Az.ps1
TargetSite :
Name : ThrowExceptionForIoErrno
DeclaringType : Interop, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
MemberType : Method
Module : System.Private.CoreLib.dll
Source : System.Private.CoreLib
HResult : -2147024894
StackTrace :
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share,
FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions,
Func`4 createOpenException)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share,
FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
at System.IO.File.ReadAllLines(String path, Encoding encoding)
at Microsoft.PowerShell.PowerShellGet.UtilClasses.PSScriptFileInfo.TryParseScriptFileContents(String scriptFileInfoPath,
List`1& psScriptInfoCommentContent, List`1& helpInfoCommentContent, List`1& requiresCommentContent, String[]&
remainingFileContent, ErrorRecord& error) in /Users/andrewsuh/PowerShellGet/src/code/PSScriptFileInfo.cs:line 118
at Microsoft.PowerShell.PowerShellGet.UtilClasses.PSScriptFileInfo.TryTestPSScriptFile(String scriptFileInfoPath,
PSScriptFileInfo& parsedScript, ErrorRecord[]& errors, String[]& verboseMsgs) in
/Users/andrewsuh/PowerShellGet/src/code/PSScriptFileInfo.cs:line 305
at Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallHelper.InstallPackage(List`1 pkgsToInstall, String repoName, String
repoUri, PSCredentialInfo repoCredentialInfo, PSCredential credential, Boolean isLocalRepo, ScopeType scope) in
/Users/andrewsuh/PowerShellGet/src/code/InstallHelper.cs:line 577
HResult : -2146233079
TargetObject : Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource
CategoryInfo : InvalidOperation: (Microsoft.PowerShel…s.InstallPSResource:InstallPSResource) [Install-PSResource],
PSInvalidOperationException
FullyQualifiedErrorId : InstallPackageFailed,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource
InvocationInfo :
MyCommand : Install-PSResource
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 6
Line : Install-PSResource -Name Az
PositionMessage : At line:1 char:1
+ Install-PSResource -Name Az
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Install-PSResource
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
Environment data
PS> Get-Module PowerShellGet; $PSVersionTable
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.2.5 PowerShellGet {Find-Command, Find-DscResource, Find-Module, Find-RoleCapa…
Binary 3.0.17 beta17 PowerShellGet {Find-PSResource, Get-PSResource, Get-PSResourceRepository,…
Key : PSVersion
Value : 7.3.0
Name : PSVersion
Key : PSEdition
Value : Core
Name : PSEdition
Key : GitCommitId
Value : 7.3.0
Name : GitCommitId
Key : OS
Value : Darwin 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct 9 20:14:54 PDT 2022; root:xnu-8792.41.9~2/RELEASE_X86_64
Name : OS
Key : Platform
Value : Unix
Name : Platform
Key : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0…}
Name : PSCompatibleVersions
Key : PSRemotingProtocolVersion
Value : 2.3
Name : PSRemotingProtocolVersion
Key : SerializationVersion
Value : 1.1.0.1
Name : SerializationVersion
Key : WSManStackVersion
Value : 3.0
Name : WSManStackVersion
Visuals
No response
Issue Analytics
- State:
- Created 9 months ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Unable to install Az powershell module with PS7 on ...
1 Answer 1 ... Trying to install az module over existing modules will give this error and it appears to be the cause...
Read more >Failed downloading Az and other modules for powershell
PackageManagement\Install-Package : Package 'Az.Accounts' failed to download. At C:\Program Files\WindowsPowershell\Modules\PowerShellGet\1.0.
Read more >[error]Could not find the modules: 'Az.Accounts' with Version
I have a release Pipeline in which I use Azure PowerShell to deploy artifacts into AppServices in Azure. It was working fine around...
Read more >Install-Module and Update-Module errors / Unable to ...
The fix for this issue appears to be to update PowerShellGet to the latest version and this is where I am having an...
Read more >Import-Module Azure fails - powershell
When I open just a plain PS window and do Import-Module Azure it fails with: import-module : The specified module 'Azure' was not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@andrewsuh98 the problem is that PSGet is finding NuGet packages from the NuGet feed, and detecting they are not PowerShell content. AFAIK there is no filter in NuGet feeds by type, so this cannot be handled during the search.
I agree the error message can be improved. Could that be a post-GA issue? This does not seem to be blocking.
We can add better error handling here for when a .nupkg package is attempted to be installed yet does not contain a .ps1 or .psd1 file (i.e it is not a PowerShell resource).