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
{
}
}
Sapien PowerShell Project Dependent Module
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.
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.
Re: Sapien PowerShell Project Dependent Module
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.
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.
SAPIEN Technologies, Inc.
Re: Sapien PowerShell Project Dependent Module
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.
Re: Sapien PowerShell Project Dependent Module
Thank you for the clarification. If you install a new module or update a module, I recommend refreshing the cache in PowerShell Studio:
In the case where the module is not located in a $env:PSModulePath folder, I recommend importing the module in the CacheEditor.
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.
SAPIEN Technologies, Inc.