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.

Feature Request: Import-PowershellDataFile should accept string input

See original GitHub issue

Summary of the new feature/enhancement

Currently Import-PowershellDataFile takes a path to a file on disk. But what if I have the .psd1 content in memory? (Such as in a string, as downloaded from AzDO or github or such.)

Proposed technical implementation details (optional)

Another parameter set that accepts a string.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
mklement0commented, Sep 25, 2020

As an alternative to a new cmdlet, we could think about generalizing @JamesWTruher’s idea proposed in the context of https://github.com/PowerShell/PowerShell/issues/4332#issuecomment-643486358: To allow targeting a variable via a provider path; e.g.:

$dataFileContent = ... # read *.psd1 file into memory

Import-PowerShellData -LiteralPath variable:dataFileContent

All file-processing cmdlets could benefit from this, notably Import-CliXml / Export-CliXml, which would obviate the need to implement #3898 (separate ConvertTo/From-CliXml cmdlets).

I’ve always felt that the current dichotomy - one cmdlet for in-memory operations, another for file operations - is clumsy, both in terms of UX and implementation.

2reactions
vexx32commented, Sep 25, 2020

Yeah looks like they explicitly check for other providers and prevent them from being used.

IMO they should just… not, really. 😂

New-WordCloud from my PSWordCloud module allows this kind of functionality (writing to arbitrary PSProviders). The only real issue I ran into was that not all providers (the variable provider is one of these) support the Content.Clear() operation, so you do have to catch that and (probably) swap it for an Item.Remove() operation instead (if the provider supports that) if you want to be able to do Set-Content style things which clear data before writing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Import-PowerShellDataFile (Microsoft.PowerShell.Utility)
The Import-PowerShellDataFile cmdlet safely imports key-value pairs from hashtables defined in a .PSD1 file. The values could be imported using ...
Read more >
Ways to input parameter values from file : r/PowerShell
I have several scripts with quite an extensive list of parameters, among which often long strings, to be used by the helpdesk who...
Read more >
Script out a hashtable with PowerShell [duplicate]
Fundamentally, converting a hashtable instance to its equivalent source-code representation only works in simple cases, such as yours.
Read more >
PowerShell Pipe Options and Functions List
The Import-PowerShellDataFile cmdlet safely imports key-value pairs from hashtables defined in a .PSD1 file. The values could be imported using ...
Read more >
PSFramework.psm1 1.4.150
Loads files into the module on module import. .DESCRIPTION This helper function is used during module initialization. It should always be dotsourced itself,...
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