Sapien PowerShell Project Dependent Module

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
dvenardos
Posts: 5
Last visit: Fri Jan 14, 2022 1:04 am

Sapien PowerShell Project Dependent Module

Post by dvenardos »

Product, version and build: PowerShell Studio 2019, 5.6.158
32 or 64 bit version of product: 64
Operating system: Windows 10 Enterprise
32 or 64 bit OS: 64

I am new to PowerShell Studio. When using a generic project for creating PowerShell functions (one function in each script file), how do you get PS Studio to load a dependent module that is installed in the default location (i.e. PowerShell ISE loads the module automatically.)?

This is what I am working on:
#Requires -Module dbatools

function New-StandardSQLFolders
{
[CmdletBinding()]
[OutputType([PSObject])]

param
(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 0)]
[ValidateNotNullOrEmpty()]
[string[]]$ComputerName
)

BEGIN
{
Write-Verbose("Getting installed SQL engine on: $ComputerName.")
$sqlEngine = Get-DbaService -ComputerName $ComputerName -Type Engine
}
PROCESS
{
foreach ($s in $sqlEngine)
{
Write-Verbose("Setting standard SQL drives for $($s.ComputerName)\$($s.InstanceName)")
}
}
END
{
}
}
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Sapien PowerShell Project Dependent Module

Post by davidc »

The module loading is handled via PowerShell engine when you run the script. You can use the requires statement or use a simple Import-Module statement within your script.

Are you getting an error message when you run your script?
Note: That each time you run a script in PowerShell Studio’s internal host, the runspace is reset. If you wish to keep a persistent runspace, then I recommend using the Run in Console commands.
David
SAPIEN Technologies, Inc.
dvenardos
Posts: 5
Last visit: Fri Jan 14, 2022 1:04 am

Re: Sapien PowerShell Project Dependent Module

Post by dvenardos »

Sorry I wasn't clear. The problem was with the IDE and not running the script. The IDE did not recognize the functions in the dbatools modules, but I found the cache editor and importing it there resolves the issue.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Sapien PowerShell Project Dependent Module

Post by davidc »

Thank you for the clarification. If you install a new module or update a module, I recommend refreshing the cache in PowerShell Studio:
Refresh Cache.png
Refresh Cache.png (33.03 KiB) Viewed 1914 times
In the case where the module is not located in a $env:PSModulePath folder, I recommend importing the module in the CacheEditor.
David
SAPIEN Technologies, Inc.
This topic is 4 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.