powershell-module

PowerShell Az module: export and import offline

只愿长相守 提交于 2021-02-11 14:41:15
问题 I need to move PowerShell Az module from one machine to another offline (both machines have the same windows (10 Pro 1809), .net, powershell (5.1), etc versions) I can't use either Private PowerShellGet Repositories or MSI installer I run Save-Module -Name Az -Path 'C:\Users\kag\Documents\ps_modules' -RequiredVersion 3.7.0 -Force on "donor" machine and it gives me 50+ dirs exported: I copy all to "receiver" machine and running: Get-ChildItem "C:\Users\kag\Documents\ps_modules\*" -Recurse |

How do I debug a Windows PowerShell module in Visual Studio?

最后都变了- 提交于 2021-01-20 18:11:04
问题 I'm trying to write a PowerShell module as a VB.NET project with Visual Studio 2015. I've been able to put a few commands together, compile the class library into a DLL, import the module into a PowerShell session and call the command I created. All good so far. But as I'm expanding this module I'm going to need to be able to debug it. So I added another project to the solution, a console application. I set it as the startup project and referenced the PowerShell class in the first project. So

How do I debug a Windows PowerShell module in Visual Studio?

一笑奈何 提交于 2021-01-20 18:09:47
问题 I'm trying to write a PowerShell module as a VB.NET project with Visual Studio 2015. I've been able to put a few commands together, compile the class library into a DLL, import the module into a PowerShell session and call the command I created. All good so far. But as I'm expanding this module I'm going to need to be able to debug it. So I added another project to the solution, a console application. I set it as the startup project and referenced the PowerShell class in the first project. So

How do I debug a Windows PowerShell module in Visual Studio?

可紊 提交于 2021-01-20 18:09:40
问题 I'm trying to write a PowerShell module as a VB.NET project with Visual Studio 2015. I've been able to put a few commands together, compile the class library into a DLL, import the module into a PowerShell session and call the command I created. All good so far. But as I'm expanding this module I'm going to need to be able to debug it. So I added another project to the solution, a console application. I set it as the startup project and referenced the PowerShell class in the first project. So

How do I debug a Windows PowerShell module in Visual Studio?

自古美人都是妖i 提交于 2021-01-20 18:09:19
问题 I'm trying to write a PowerShell module as a VB.NET project with Visual Studio 2015. I've been able to put a few commands together, compile the class library into a DLL, import the module into a PowerShell session and call the command I created. All good so far. But as I'm expanding this module I'm going to need to be able to debug it. So I added another project to the solution, a console application. I set it as the startup project and referenced the PowerShell class in the first project. So

Call a specific version of PowerShell from C#

拟墨画扇 提交于 2020-01-11 13:06:28
问题 I'm trying to use the Get-VM Cmdlet called from C# on a Hyper-V host. Obviously, the according PowerShell module Hyper-V has to be imported first. The import fails, however - apparently because the module is supported only on PowerShell 3.0 (at least that's what I figure from this article). The PowerShell used by System.Management.Automation seems to be version 2.0, though. InitialSessionState iss = InitialSessionState.CreateDefault(); iss.ImportPSModule(new string[] { "Hyper-V" }); Runspace

Call a specific version of PowerShell from C#

一曲冷凌霜 提交于 2020-01-11 13:06:08
问题 I'm trying to use the Get-VM Cmdlet called from C# on a Hyper-V host. Obviously, the according PowerShell module Hyper-V has to be imported first. The import fails, however - apparently because the module is supported only on PowerShell 3.0 (at least that's what I figure from this article). The PowerShell used by System.Management.Automation seems to be version 2.0, though. InitialSessionState iss = InitialSessionState.CreateDefault(); iss.ImportPSModule(new string[] { "Hyper-V" }); Runspace

Export Powershell 5 enum declaration from a Module

断了今生、忘了曾经 提交于 2020-01-02 02:40:30
问题 I have an enum type defined within a module. How do I export it to be accessible from outside once the module has been loaded? enum fruits { apple pie } function new-fruit { Param( [fruits]$myfruit ) write-host $myfruit } My advanced function takes the enum instead of the ValidateSet which works if the enum is available, but fails if it isn't. Update: Separating it into a ps1 and dot-sourcing it (ScriptsToProcess) works, however I would wish that there's a cleaner way. 回答1: You can access the

How do I force powershell to reload a custom module?

只谈情不闲聊 提交于 2020-01-01 22:47:50
问题 I have created a module 'ActiveDirectory.psm1' which contains a class in powershellv5. I am importing that module in another file called 'test.ps1' and then calling a method from the class. test.ps1 contains the following: using module '\\ser01\Shared\Scripts\Windows Powershell\modules\ActiveDirectory\ActiveDirectory.psm1' Set-StrictMode -version Latest; $AD = [ActiveDirectory]::New('CS'); $AD.SyncGroupMembership($True); It all works as expected BUT when I make a change to ActiveDirectory

PowerShell module terminating unexpectedly

陌路散爱 提交于 2019-12-25 07:47:48
问题 A PowerShell module I'm working on is behaving very strangely... I have the following code in a RestoreTestFiles.psm1 file (located in %USERPROFILE%\My Documents\WindowsPowerShell\Modules\RestoreTestFiles\ ): Function Restore-TestFiles([string]$backupDir, [string]$destinationDir, [bool]$overwrite) { if (!(Test-Path $backupDir)) { Write-Host "Error, $backupDir does not exist." return } if ($backupDir.EndsWith("\*")) { Write-Host "$backupDir ends with \*!" } else { Write-Host "$backupDir does