230 questions
1
vote
0
answers
74
views
Modules moved to custom user PSModulePath not recognized
I specified the PSModulePath in %ONEDRIVE%\Documents\PowerShell\powershell.config.json and then restarted the computer.
A new PowerShell session showed the custom PSModulePath via $env:PSModulePath ...
1
vote
1
answer
63
views
How to determine the calling script from deep inside a manifest module?
Let's assume I am calling a script called script.ps1
It loads a module called DoStuff, it calls the Do-WorkPart1 cmdlet from that module
Inside DoWork.psm1 file that is part of the manifest, I want to ...
2
votes
2
answers
141
views
Why are variables NOT exported, despite being listed under VariablesToExport in the manifest of a PS module?
The manifest variable export
VariablesToExport = @(
"ERROR_SUCCESS_REBOOT_REQUIRED",
"ERROR_SUCCESS",
"ERROR_INVALID_FUNCTION",
"...
0
votes
0
answers
37
views
How to write a PS manifest module with lots ps1 files and all cmdlets can be used inside the Module without exporting? [duplicate]
cmdlets that are used by customer of this module will need to be exported.
2 files
file1.ps1
function Yes() {
DoSomthing
}
file2.ps1
function DoSomthing() {
}
Ass DoSomthing is called from file1 ...
1
vote
1
answer
63
views
Converting a script module to a manifest one. But each file doesn't have access to each cmdlet without exporting it
In the script module, with 98 ps1 filles. Each file had access to each cmdlet from each file without needing to explicitly export them.
But in the manifest module, only the cmdlets that have been ...
0
votes
0
answers
44
views
How to set global PS variable in a manifest
I am converting a script module to a manifest module.
In the script module I do the below at the end
#
# Whole module Verbose output
#
# We will output verbose "Continue"
# We will NOT ...
0
votes
0
answers
35
views
PowerShell Binary Module Dependencies
If I publish my C# Binary PowerShell module like this, it works.
dotnet publish -c Release
Push-Location ".\Module\bin\Release\net7.0\publish"
Publish-Module -Name .\ImportIcal.psd1 -...
0
votes
1
answer
25
views
Powershell module class usage within a class
I have a script like this, in a classes.psm1 file:
class A {
A([string] s) { }
}
class B : A {
B([string] s) : base($s)
}
Then I try to import it in a .ps file:
using module classes.psm1
...
-3
votes
1
answer
123
views
How to get a list of functions in a PowerShell Gallery package after installation?
How to get a list of PowerShell functions in a newly installed PowerShell package from the PowerShell Gallery?
I just installed a package via Install-Module -Name ModuleName. I would like to be able ...
1
vote
1
answer
101
views
How to prevent loading of .psd1 RequiredModules when Import-Module fails?
When importing a module fails, it will still load the RequiredModules defined in the .psd1 manifest.
Consider the following module files:
MyModule.psd1
@{
RootModule = 'MyModule.psm1'
...
0
votes
0
answers
1k
views
Installing UIAutomation PowerShell Module
I would like to install the UIAutomation PowerShell module on my PowerShell ISE. I have used the following command for this:
Install-Module -Name UIAutomationClient
or
Install-Module -Name ...
0
votes
1
answer
525
views
How to autoload a module in PowerShell
In Windows PowerShell (version 5.1.19041.4894) what should I do to have modules loaded? This
is in the $Env:PSModulePath: D:\Users\theking2\OneDrive\Documents\WindowsPowerShell\Modules;.....
The ...
1
vote
1
answer
154
views
Get-AzKeyVaultSecret doesn't work when in a function
I have a .psm1 module file that has a few helper functions for the run.ps1 script.
In one of the functions, I'm accessing Azure Key Vault to grab a connection secret; this is where the run.ps1 seems ...
2
votes
2
answers
110
views
`Get-PSSubsystem` is not recognized
PS C:\> Get-PSSubsystem causes error
Get-PSSubsystem: The term 'Get-PSSubsystem' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the ...
0
votes
1
answer
435
views
AppContext.BaseDirectory in C# PowerShell module returns unexpected path
I have a PowerShell module written in C#. I have a "Assets" directory with some files as part of the module. When I publish the module to a local directory, it has structure like this:
|- ...
0
votes
0
answers
270
views
PowerShell Repository in Artifactory - Module not found
I am trying to setup a PowerShell repository for private modules on Artifactory based on this article:
https://jfrog.com/help/r/how-to-work-with-powershell-modules-and-nuget-repository/how-to-work-...
1
vote
1
answer
153
views
How to troubleshoot a Module Manifest?
I have a small PowerShell module that loads fine without a psd1 file. As soon as a psd1 file is in the root of the module folder, the module fails to (auto) load without error. Also Test-...
1
vote
1
answer
1k
views
SQL Server does not recognize new Powershell SqlServer module
Uninstalled the old PS module, downloaded the nuget package for the new 22.2 SqlServer, copied the files over the server which is offline, extracted the files into the modules folder but SQL Server is ...
1
vote
1
answer
587
views
Windows PowerShell 5.1 cannot import local module file with `using module` but Pwsh 7 can
I have the following directory structure:
└─ScriptModuleRepositoryTemplate
│ ScriptModuleRepositoryTemplate.psd1
│ ScriptModuleRepositoryTemplate.psm1
│ ScriptModuleRepositoryTemplate....
2
votes
1
answer
2k
views
Problem running PS module based on .NET 8 in PowerShell 7.2
I have a PowerShell module written in C#. Recently I upgraded it to .NET 8.
My project file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<...
1
vote
2
answers
326
views
Azure Automation Custom Module not Exporting Commands
I am trying to use a custom PowerShell module in an Azure Automation account.
I have prepared the module and tested it locally. It is loaded and the commands can be used.
However, when I pack and ...
1
vote
0
answers
262
views
Cant load a particular module in Powershell
I am trying to use
[Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext] as follows:
$authContext =
[Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]$authUrl
...
1
vote
1
answer
181
views
Get-InstalledModule Command Not Working Remotely
There seems to be some issue with the PowerShell Command Get-InstalledModule.
E.g When I log in locally to a Windows server (PowerShell 5.1) and execute command Get-InstalledModule -Name Az it works ...
2
votes
1
answer
606
views
Understanding 'Powershell Runtime' and 'PowerShell Compile Time', Optimal method for sharing a class across multiple modules and scripts
So I finally finished building a class/type but now I am stumped on how to actually deploy it at the places I need. The class is supposed to provide a general purpose type, called Filmcode. I have a ...
0
votes
1
answer
390
views
Import-module : The script failed due to call depth overflow
Working on a PowerShell module and noticed I'm having an issue when attempting to import it, no matter how
import-Module -Name ".\0.0.1\PSSymantecSEPM.psd1" -Force
An error occurred while ...
1
vote
1
answer
286
views
What members do I need to add to a PowerShell module manifest file in order to export Cmdlets from multiple files?
Currently, I have a number of *.ps1 Cmdlet files, each providing a different function, e.g.:
Encode-File.ps1
Decode-File.ps1
Now, I want to convert these into a single module, so I can have their ...
2
votes
1
answer
161
views
C# binary PowerShell Module Type conversion
I'm working on a project, where I use the input properties to create parameters on objects with strong types. I have this sample code:
using System;
using System.Management.Automation;
using System....
1
vote
1
answer
1k
views
Install Powershell module as normal user
I want to use the Get-ADUser module to retrieve data from the AD domain.
Non-Administrator permissions in the directory are sufficient to perform that action.
Locally, Administrator permissions are ...
3
votes
1
answer
183
views
Powershell 5.1: alias descriptions are missing in my module
I have a module PhriInfrastructure which codifies our DevOps procedures at my organization. It has a function Test-IsLocalhost that I've aliased to Get-IsLocalhost for backwards-compatibility reasons....
3
votes
2
answers
440
views
PowerShell module with class defined in separate file fails Pester tests in GitHub Actions
I am creating a PowerShell module that defines a class. For example:
class MyClass
{
[string] $Name
}
If I put the class definition directly in the psm1 file then everything works fine. However, ...
1
vote
3
answers
484
views
How to create dynamic block in powershell, that calls script functions?
I'm trying to generate a dynamic UI. I haven't been able to add an OnClick event dynamically. Here's a sample
function Say-Hello
{
Param (
[Parameter(Mandatory=$true)]
[...
1
vote
2
answers
130
views
How do I read the "using module" statements in a powershell script?
Powershell 5 has a nice declarative "using module" statement that can be provided at the top of a file to declare the dependencies of the script. Presumably one should be able to use this ...
1
vote
3
answers
2k
views
SmbShare: the module could not be loaded
The Problem:
I have inherited a PS script file that deletes a directory. In case there are any locks on it, it removes them using this line:
Get-SmbOpenFile | Where-Object -Property Path -Like "$(...
0
votes
0
answers
56
views
Calling function with typed parameter from outside module
I have a Powershell module ExportHelper.psm1 in which I define a custom class Text and a function Add-Text:
class Text {
[string]$value
[Format]$format
}
function Add-Text {
Param([Text]$text)
...
1
vote
1
answer
32
views
Displaying logs from when calling external commands from a powershell script
In a powershell module there is a class with the following method (here simplified). It simply calls docker to automatically build an image.
Everything works and the image is correctly built. What I ...
0
votes
1
answer
430
views
PowerShell module ImportExcel only returning up to column AF2 when many other columns available to the right of AF2
I am using the PowerShell module ImportExcel from here: https://github.com/dfinke/ImportExcel
To eliminate my complex code I am just running the following: (xxx indicates folders I dont want to show)
$...
0
votes
0
answers
64
views
Is it possible to use 2 separate modules inside of a Powershell runspace?
Is it possible to import the Exchange OnPrem and Exchange Online modules into a single runspace? I've been trying the below and then only receiving the on prem data? I want to ensure that I'm not ...
1
vote
0
answers
72
views
Adding tab completion to the ItemType parameter of "New-Item" for a custom PowerShell provider
I am creating a custom PowerShell provider using PowerShellStandard.Library.
When implementing the New-Item cmdlet, I would like to be able to provide support for argument completion of the -ItemType ...
0
votes
0
answers
14
views
How to Remove the column heading while fetching the excel sheet data through the PowerShell [duplicate]
While fetching the data from the excel through the PowerShell, along with that we are getting the column heading and datatype is "PSCustomObject".
so can any one help to remove the column ...
1
vote
1
answer
2k
views
Is it possible to Install-Module from public GitHub Packages location?
I have been able to successfully publish a PowerShell module of my own creation to the repo's GitHub Packages location. I have utilized several resources to get that accomplished.
The problem comes in ...
5
votes
1
answer
4k
views
How does Powershell Auto-Load Modules?
We learn that Powershell introduced Module Auto-Loading in 3.0 :
... PowerShell imports modules automatically the first time that you
run any command in an installed module. You can now use the
...
1
vote
1
answer
5k
views
How to run my PowerShell module cmdlet as SYSTEM?
Created a PowerShell module, it has a function and exposes a cmdlet for that function. the built-in PowerShell 5.1 and pwsh.exe 7.3.1 (Installed using MSI installer) can detect and run the cmdlet ...
0
votes
1
answer
640
views
"Unable to find type" when mocking class in a Powershell unit test
I am creating a module which contains a class file as well as a unit test file (Pester).
The class B in the class file inherits from a class A found in another module.
If I try to run a unit test that ...
0
votes
1
answer
3k
views
How to install the Powershell Module MicrosoftPowerBIMgmt with offline?
I want to install the Powershell Module MicrosoftPowerBIMgmt with below command line:
Install-Module -Name MicrosoftPowerBIMgmt
However, the script is executed, but it may be limited by my network, ...
3
votes
1
answer
873
views
Commandlets from a custom Module not being recognised
I have a custom Powershell module I have been working on for the past few days, I am now trying to integrate it into powershell as a module that always gets auto loaded.
My module is placed under the ...
3
votes
3
answers
2k
views
Powershell Module name
I am working on a powershell module that has many cmdlets. I've been asked if we can add something to the cmdlets to prevent namespace collisions between modules. One thing that has been proposed if ...
0
votes
0
answers
309
views
Creating a PowerShell module from files
I have seen this question here but there not working for me.
I currently have taken apart a psm1 file with 200 functions and separated them into individual files.
Functions are separated into public ...
1
vote
1
answer
1k
views
Powershell script from Docker Container
I am trying to run a simple powershell script from a docker container. The script is supposed to create an AD group.
The problem I am facing is that the ActiveDirectory module is not available, which ...
0
votes
2
answers
2k
views
Job Suspended Run Login-AzureRmAccount to login using Azure AutomationAccounts System Managed Identity
I am trying to shutdown the VM using Azure Automation Account System Managed identity option.
However I am ending up with below error.
As per the other articles it is mentioned to upgrade the module ...
1
vote
0
answers
28
views
Why do I have to open a new powershell window to get the changes to my psm1 files? [duplicate]
I've written some code in powershell modules, and when my .ps1 file Imports them, it works with a fresh window; but if I stop the script, make some changes to the modules, and re-run the script...for ...