question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Get-InstalledPSResource` does not return scripts

See original GitHub issue

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

Seems #1187 was closed prematurely, this has not been fixed in v0.5.23-beta23.

This is not the same as the feature request for adding -Type to said cmdlet ( #1075 ): Not specifying -Type should return any PSResource, which includes both scripts and modules.

Script to reproduce:

Click to expand
#Requires -Version 5.1
<#
    .SYNOPSIS
        Reproduce the issue that Microsoft.PowerShell.ResourceGet\Get-PSResource does not return scripts.

    .NOTES
        Author:   Olav Rønnestad Birkeland | github.com/o-l-a-v
        Created:  230804
        Modified: 230804

    .EXAMPLE
        # Run from PowerShell ISE or VSCode with the PowerShell extension
        & $(Try{$psEditor.GetEditorContext().CurrentFile.Path}Catch{$psISE.CurrentFile.FullPath}) | clip
#>


# Input parameters
[OutputType([System.Void])]
Param()


# PowerShell preferences
$ErrorActionPreference = 'Stop'
$InformationPreference = 'Continue'


# Assets
$TempDir    = [string] '{0}\Temp\Testing\{1}\Scripts' -f $env:LOCALAPPDATA, [datetime]::Now.ToString('yyyyMMddHHmmss')
$ScriptName = [string] 'Get-WindowsAutoPilotInfo'


# Create temp path
Write-Information -MessageData ('{0}# Create temp path' -f [System.Environment]::NewLine)
if (-not [System.IO.Directory]::Exists($TempDir)) {
    $null = [System.IO.Directory]::CreateDirectory($TempDir)
}


# Import Microsoft.PowerShell.PSResourceGet
Write-Information -MessageData ('{0}# Import Microsoft.PowerShell.PSResourceGet' -f [System.Environment]::NewLine)
$null = Import-Module -Name 'Microsoft.PowerShell.PSResourceGet'
Write-Information -MessageData (
    Get-Module -Name 'Microsoft.PowerShell.PSResourceGet' | `
        Format-Table -Property 'ModuleType','Version',@{'Name'='PreRelease';'Expression'={$_.'PrivateData'.'PSData'.'Prerelease'}},'Name' | `
        Out-String
)


# Save $ScriptName to temp path
Write-Information -MessageData ('{0}# Save $ScriptName to temp path' -f [System.Environment]::NewLine)
$null = Save-PSResource -Name $ScriptName -SkipDependencyCheck -Path $TempDir -Repository 'PSGallery' -TrustRepository


# List files in $TempDir
Write-Information -MessageData ('{0}# List files in $TempDir' -f [System.Environment]::NewLine)
Write-Information -MessageData (([System.IO.Directory]::GetFiles($TempDir) -as [string[]]) -join [System.Environment]::NewLine -as [string])


# Get PSResources in $TempDir
Write-Information -MessageData ('{0}# Get PSResources in $TempDir' -f [System.Environment]::NewLine)
Get-InstalledPSResource -Path $TempDir

Output of this script when testing:

Click to expand
PS C:\Users\olav.birkeland\OneDrive\IT\Code\PowerShell>         & $(Try{$psEditor.GetEditorContext().CurrentFile.Path}Catch{$psISE.CurrentFile.FullPath}) | clip

# Create temp path

# Import Microsoft.PowerShell.PSResourceGet

ModuleType Version PreRelease Name
---------- ------- ---------- ----
    Binary 0.5.23  beta23     Microsoft.PowerShell.PSResourceGet



# Save $ScriptName to temp path

# List files in $TempDir
C:\Users\olav.birkeland\AppData\Local\Temp\Testing\20230804111230\Scripts\Get-WindowsAutoPilotInfo.ps1

# Get PSResources in $TempDir
Get-InstalledPSResource: C:\Users\olav.birkeland\OneDrive\IT\Code\PowerShell\Various\Error reports\PSResourceGet\230804 - PSResourceGet 3 beta 23 - Get-PSResource does not return scripts.ps1:61:1
Line |
  61 |  Get-InstalledPSResource -Path $TempDir
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Error cannot find expected subdirectories in provided path: C:\Users\olav.birkeland\AppData\Local\Temp\Testing\20230804111230\Scripts
PS C:\Users\olav.birkeland\OneDrive\IT\Code\PowerShell>

Expected behavior

It should return scripts too.

Actual behavior

It does not return scripts.

Error details

No response

Environment data

Microsoft.PowerShell.PSResourceGet v3 beta 23
PowerShell x64 v7.3.6 installed with MSI

Visuals

image

Issue Analytics

  • State:closed
  • Created 2 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alericksoncommented, Aug 11, 2023

I just tested and I’m not getting the XML file when I use Save-PSResource -IncludeXML on a script, so I think that’s the bug here. I’ll open a new issue with that problem specifically.

1reaction
o-l-a-vcommented, Aug 9, 2023

I use save to overwrite where it installs to, as I don’t want modules and scripts installed to OneDrive if known folder move is enabled and I install in user context.

  • Microsoft.PowerShell.PSResouceGet still does not respect PSModulePath, right?

Save-PSResource has a switch for including XML, but no XML is added when saving a script. So maybe the bug is that Save-PSResource -IncludeXml does not create the XML file?

Read more comments on GitHub >

github_iconTop Results From Across the Web

3.0-Approved Milestone
PowerShellGet is the package manager for PowerShell - 3.0-Approved ... Find-PSResource Type parameter does not return Script types if Name contains wildcard ......
Read more >
Google Apps Script: The script completed but did not return ...
I would add some Logger.log() to see what exactly you are appending: function doGet(e) { var healthSheet = SpreadsheetApp.
Read more >
Locking Down Your Website Scripts with CSP, Hashes ...
This is why a CSP turns off script blocks by default. ... But that means you can't return a hash because you simply...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found