Questions tagged [powershell-module]

Powershell Modules are sets of related Windows PowerShell functionalities that can be dynamic or persist on disk. Modules can contain cmdlets, providers, functions, variables, aliases and PowerShell drives.

A Powershell Module is a set of related Windows PowerShell functionalities that can be dynamic or persist on disk. Modules that persist on disk are referenced, loaded, and persisted as script modules, binary modules, or manifest modules.

Related Cmdlets

  • ImportSystemModules
  • New-Module
  • Import-Module
  • Export-ModuleMember
  • Get-Module
  • Remove-Module
  • New-ModuleManifest
  • Test-ModuleManifest
203 questions
3
votes
0 answers

Splitting up module functionality into separate files

I'm new to modules and want to split up a lengthy .psm1 file into multiple files for maintainability. What is the best way to do this? I've got it working using dot sourcing but I suspect there is a better way of creating a module with multiple…
Simon Elms
  • 17,832
  • 21
  • 87
  • 103
3
votes
2 answers

PowerShell 5 class: Import module needed for type

I have a written a PowerShell 5 class: class ConnectionManager { # Public Properties static [String] $SiteUrl static [System.Management.Automation.PSCredential] $Credentials static [SharePointPnP.PowerShell.Commands.Base.SPOnlineConnection]…
Patric
  • 2,789
  • 9
  • 33
  • 60
3
votes
1 answer

How to invoke script-module cmdlet from a binary cmdlet?

I am writing a Powershell cmdlet in C# by inheriting from PSCmdlet. This is part of a powershell module which contains both binary and script components. I want to be able to invoke a script module cmdlet from within my binary cmdlet. I've worked…
Jack Ukleja
  • 13,061
  • 11
  • 72
  • 113
3
votes
0 answers

Test-ModuleManifest fails on environment variables in module

I have an internal PowerShell repository which is utilises the Package Management capabilities of PowerShell 5.x. I hit an issue with Test-ModuleManifest which is called behind the scenes when running Publish-Module. The use of $env:ProgramFiles in…
3
votes
2 answers

Cannot call exit() from a method within a custom object

I'm trying to emulate classes using PS modules as described in this answer. However, it doesn't seem possible to exit from within such an "instance method": $sb = { function bar { "bar" } function quux { exit …
Adrian Frühwirth
  • 42,970
  • 10
  • 60
  • 71
3
votes
3 answers

install Active Directory module powershell for windows 10

Good afternoon! I need to add only the module rsat Active Directory module powershell in windows 10 Execute command: Enable-WindowsOptionalFeature -Online -FeatureName RSATClient-Roles-AD-Powershell But error: Enable-WindowsOptionalFeature : Не…
user3919982
  • 31
  • 1
  • 1
  • 2
3
votes
1 answer

can a New-Module return a psobject?

This module below returns a empty object . Any suggestions to fix it ? New-Module -ScriptBlock { $resourcesDirectory="AA" ..... $commonProperties = New-Object PSObject -Property @{ ResourcesDirectory = $resourcesDirectory …
petercli
  • 629
  • 1
  • 8
  • 27
3
votes
2 answers

The Powershell Command "Get-DistributionGroup" doesn't work

The Get-DistributionGroup command is supposed to list distribution groups in a domain but I can't get it to run on my server. After some Googling I found that Import-Module ActiveDirectory needs to be run first, but what I get when I run that…
Tensigh
  • 1,030
  • 5
  • 22
  • 44
3
votes
1 answer

Powershell binary module: Dynamic tab completion for Cmdlet parameter values

I'm writing a binary Powershell module in C# and I'd like to have a Cmdlet with a parameter that provides dynamic, run-time tab completion. However, I'm struggling to figure out how to do this in a binary module. Here's my attempt to get this…
Dan Stevens
  • 6,392
  • 10
  • 49
  • 68
3
votes
0 answers

Module helper function not recognized in nested modules

I have a Powershell module that consists of 4 .psm1 files: DatabaseUserManagement.psm1 - Contains most of my public cmdlets. PermissionControl.psm1 - Contains the final public cmdlet. ErrorHandling.psm1 - Contains a private error handling function.…
Jake
  • 1,701
  • 3
  • 23
  • 44
3
votes
2 answers

ValidateScript ParameterAttribute in C# Binary PowerShell Module

I have recently begun experimenting with Binary PowerShell Programming in C#, and I am having some trouble with ParameterValidationAttributes, the ValidateScript Attribute mostly. Basically, i want to create a Param named "ComputerName" and…
tomohulk
  • 592
  • 2
  • 9
  • 22
3
votes
1 answer

Get working directory in binary powershell module

I'm writing a binary powershell module in C# and I can't seem to find out to get the current working directory from within a command. My first thought was to do a simple Directory.GetCurrentDirectory(); from the System.IO library but it only seems…
jonfriesen
  • 625
  • 6
  • 19
3
votes
3 answers

Combine Powershell Scripts into a module

I have a half dozen powershell scripts (.ps1 files) that all have related functionality. Is there an easy way that I can combine them into a module so that I can call them like they were normal CmdLets ? For example, insteading of running: PS>…
A.R.
  • 15,405
  • 19
  • 77
  • 123
3
votes
1 answer

PowerShell .ps1 file cmdlets in a module

Right now I have a collection of .ps1 PowerShell script cmdlets (they can take parameters) that are related to each other, but each is fairly involved. I'd like to organize them into a module, preferably while keeping them in separate files. What is…
Ryan Hiebert
  • 571
  • 1
  • 5
  • 17
2
votes
2 answers

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, if I move the class to its own file and include…
deadlydog
  • 22,611
  • 14
  • 112
  • 118