标签: powershellget

为PowerShellGet创建纯PowerShell Nuget模块

我想要的是

我想将许多PowerShell脚本发布为构建系统上使用的Nuget包.

我想使用PowerShellGet为我和版本管理做安装工作.

我不希望这些脚本成为任何Visual Studio解决方案的一部分,而是作为独立脚本.

使用场景

在任何系统上,配置的Nuget提供程序用户执行:

Install-Module MyModule
Run Code Online (Sandbox Code Playgroud)

从那时起,该模块的所有导出将永久可供该用户使用.用户也可以再次调用该命令来更新这些脚本的版本.

我做了什么

你可以在这里找到当前的包状态:GitHub

  1. 我已将Nuget提供程序添加并配置到我们的本地Nuget服务器

    要做这个电话Get-PackageProvider -Name NuGet -ForceBootstrapSet-PSRepository -Name My_Nuget_Repo -SourceLocation http://my-nuget/api -InstallationPolicy Trusted

  2. 创建了适当的模块,可以通过本地导入 Import-Module
  3. 使用该模块创建并发布了Nuget包

问题

我可以通过Install-Modulecmdlet 安装该软件包,稍后我会在Get-InstalledModule列表中看到它.

但是,没有可用的功能.

此外,无论如何,但Install-Module不从我的包中调用任何脚本:

  • 不调用ScriptsToProcessMyModule.psd1
  • 没有Install.ps1tools文件夹调用
  • 没有Init.ps1tools文件夹调用
  • 模块导出的Cmdlet不可用,模块无法导入 Import-Module

(从Visual Studios安装时,相同的包正常工作Install-Package MyModule,调用脚本,导入PowerShell模块).

调查

因为PowerShellGet基于OneGet它似乎问题是在Install-Packagecmdlet(在cmdlet中调用Install-Module). …

powershell nuget oneget powershellget

10
推荐指数
1
解决办法
3930
查看次数

PowerShell 包管理 - 存储库 vs 提供者 vs 源代码

我正在尝试了解 PowerShell 中的包管理,但得到的图片不完整。当我查看对象 PSRepository、PackageProvider 和 PackageSource 时,它​​们似乎都具有以下关系:

  • PSRepository可以提供零个或多个PowerShell模块。一个PSRepository必须只有一个PackageProvider。存储库的一个示例是PSGallery.
  • 一个PackageProvider可以成为零个或多个PSRepository对象。一个PackageProvider必须有一个或多个PackageSource对象。一个PackageProvider有时也被称为“包管理器”。包提供的一些实例包括NuGetChocolatey,或PowerShellGet
  • 一个PackageSource必须服务一个且仅一个PackageProvider。的包源的一些实例包括nuget.orgMyCustomVSTSFeed,或PSGallery

我查看了以下链接,但它仍然没有提供它们之间关系的清晰图片。

  1. 为什么PSRepository有一个名为PackageManagementProvider的属性,它的类型是string 而不是PackageProvider类型?
  2. 为什么PSRepository有自己的SourceLocation属性,如果它已经通过其提供者有一个源引用?
  3. 为什么PSGallery既是PackageSource又是PSRepository
  4. 为什么PowerShellGet提供对库的访问的模块的名称和PackageProvider的名称?

windows powershell package-management nuget powershellget

9
推荐指数
1
解决办法
844
查看次数

如何将模块安装到自定义目录中?

目前我们正在使用下面的命令安装一些模块,但它在C:\Program Files\WindowsPowerShell\Modules.

Install-Module -Name XXX -RequiredVersion XXX -Repository XXX -Scope AllUsers
Run Code Online (Sandbox Code Playgroud)

我们的要求是在E:\Modules文件夹中安装这个模块。为此,我更新了PSModulePath环境变量,如下所示。( https://msdn.microsoft.com/en-us/library/dd878350(v=vs.85).aspx )

$p = [Environment]::GetEnvironmentVariable("PSModulePath")
$p += ";E:\Modules"
[Environment]::SetEnvironmentVariable("PSModulePath",$p)
Run Code Online (Sandbox Code Playgroud)

但它仍然安装在C:\Program Files\WindowsPowerShell\Modules.

如何更新PSModulePathE:\Modules安装模块之前?

powershell powershell-module powershellget

8
推荐指数
2
解决办法
7582
查看次数

PowerShell v5 - 如何将模块安装到没有互联网连接的计算机?

我有一台机器(v3,互联网,没有管理员访问权限)我用来下载WMF 5.0并设置另一台机器(v5,没有互联网,管理员访问).现在,我想在运行v5但没有互联网连接的机器上使用PowerShellGet中的一些模块.

我需要一个选项来下载*.psm1文件,然后我可以复制并使用它.就像我们有从GitHub下载的选项一样.

任何有类似问题和任何变通方法的人?

powershell powershell-5.0 powershellget

7
推荐指数
1
解决办法
2万
查看次数

Register-PSRepository上的Web Uri错误无效

在Windows 11月更新(PackageManagement以及PowerShellGet1.0.0.1版本的模块)之后,我无法再将HTTPS NuGet服务器注册为PSRepository:

Register-PSRepository -Name test -SourceLocation https://some-nuget/api/v2
Run Code Online (Sandbox Code Playgroud)

它返回错误:

# Register-PSRepository : The specified Uri 'https://some-nuget/api/v2' for parameter 'SourceLocation' is an invalid Web Uri. Please ensure that it meets the Web Uri requirements.
Run Code Online (Sandbox Code Playgroud)

powershell oneget powershellget

7
推荐指数
2
解决办法
5488
查看次数

Install-PackageProvider无法识别为cmdlet,函数,脚本文件或可运行程序的名称

我正在关注PowerShell Gallery入门,其中指出PowerShellGet模块存在于Windows 10中(我正在使用它 - build 14721).要确认,我正在运行PowerShell v5:

>$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.0.14271.1000
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14271.1000
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Run Code Online (Sandbox Code Playgroud)

PowerShell库入门指出:

PowerShellGet还要求NuGet提供程序与PowerShell库一起使用.如果NuGet提供程序不在以下位置之一,则会在首次使用PowerShellGet时自动安装NuGet提供程序:•$ env:ProgramFiles\PackageManagement\ProviderAssemblies
•$ env:LOCALAPPDATA\PackageManagement\ProviderAssemblies

我在这些地方没有任何东西:

>ls $env:LOCALAPPDATA\PackageManagement\ProviderAssemblies    
>ls $env:ProgramFiles\PackageManagement\ProviderAssemblies
ls : Cannot find path 'C:\Program Files\PackageManagement\ProviderAssemblies' because it does not exist.
At line:1 char:1
+ ls $env:ProgramFiles\PackageManagement\ProviderAssemblies
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Program File...viderAssemblies:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
Run Code Online (Sandbox Code Playgroud)

开始使用PowerShell Gallery然后说明:

或者,您可以运行Install-PackageProvider -Name NuGet …

powershell powershellget

7
推荐指数
3
解决办法
1万
查看次数

PowerShell 安装模块命令未失败但未安装模块

我正在尝试将 SharePoint 的 PnP 在线命令安装到我的 PowerShell 上,但是以下命令似乎不起作用;

Install-Module -name SharePointPnPPowerShellOnline -scope CurrentUser
Run Code Online (Sandbox Code Playgroud)

该命令似乎运行良好,没有出现任何错误,但是当我尝试运行应该已安装的命令时,我收到一条错误消息,指出找不到命令。

connect-pnponline : The term 'connect-pnponline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of        
the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ connect-pnponline
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (connect-pnponline:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)

我查看了所有模块文件夹,但该模块不在其中任何一个中。我将我的环境路径与具有此功能的同事进行了比较,发现它们是相同的。

有谁知道可能是什么原因造成的?

powershell sharepoint-online powershellget

7
推荐指数
1
解决办法
7809
查看次数

如何从本地文件夹安装/更新Powershell模块-设置内部模块存储库

我需要在一个生产盒上安装PowerShell模块(即sqlserver),但是生产服务器没有任何Internet连接。

我使用的另一种方法是使用save-module将模块文件保存到共享文件夹中,然后将文件从共享文件夹直接复制到生产服务器的PS模块路径中

c:\program files\WindowsPowerShell\Modules
Run Code Online (Sandbox Code Playgroud)

它可以工作,但是我只是想知道我们是否可以使用现有的方法,即安装模块,例如

install-module -name sqlserver -repository "my shared folder"
Run Code Online (Sandbox Code Playgroud)

该要求也扩展到更新模块。

使用保存模块然后进行复制和粘贴似乎非常不可靠,因为我不知道安装模块是否实际上会进行某些DLL文件注册或安装。

任何PS专家都可以提出一些建议,例如在没有Internet连接的情况下使用安装模块吗?

在此先感谢您的时间。

PS:我知道在SO上有个职位,但这对我没有帮助。

powershell powershellget

6
推荐指数
1
解决办法
4813
查看次数

Powershell 不从模块导入函数

我正在尝试在此处设置 NuGet Feed,效果很好。我通过我的提要安装了一个模块

Install-Module -Name MyCmdlets -Repository $RepoName -Scope CurrentUser -Force
Import-Module -Name MyCmdlets
Run Code Online (Sandbox Code Playgroud)

但是,当我运行 Get-Module 时,我没有任何功能,它是一个清单?

ModuleType Version    Name                                ExportedCommands                                  
---------- -------    ----                                ----------------                                  
Manifest   1.0        MyCmdlets          
Run Code Online (Sandbox Code Playgroud)

如果我手动转到安装位置并手动导入

Import-Module <my-path>\1.0\MyCmdlets.psm1                 

ModuleType Version    Name                                ExportedCommands                                  
---------- -------    ----                                ----------------                     
Script     0.0        MyCmdlets                      {Create-Project, Get-AuditLogs, Get-..             
Run Code Online (Sandbox Code Playgroud)

我的清单文件确实有这些行,所以我不明白为什么Import-Module不能正常工作。

FunctionsToExport = '*'

CmdletsToExport = '*'

powershell cmdlets module powershell-module powershellget

4
推荐指数
1
解决办法
3202
查看次数

为什么 Find-Package 在我的本地包源上找不到按名称的包

我有一个本地包源来处理一些事情。我创建了一个名为 的脑死包CoolUtils,并使用nuget add. 您可以使用 nuget 找到它:

PS> nuget list -source E:\nuget-repo-test-01\
CoolUtils 2.0.20171024.1

PS> nuget list coolutils -source E:\nuget-repo-test-01\
CoolUtils 2.0.20171024.1
Run Code Online (Sandbox Code Playgroud)

但是,Find-Package无法按名称找到它,但可以使用通配符或未指定名称找到它:

PS> Find-Package -Source E:\nuget-repo-test-01\

Name                           Version          Source                           Summary
----                           -------          ------                           -------
CoolUtils                      2.0.20171024.1   E:\nuget-repo-test-01\           Test package with dumb scripts.

PS> Find-Package *cool* -Source E:\nuget-repo-test-01\

Name                           Version          Source                           Summary
----                           -------          ------                           -------
CoolUtils                      2.0.20171024.1   E:\nuget-repo-test-01\           Test package with dumb scripts.

PS> Find-Package CoolUtils -Source E:\nuget-repo-test-01\
Find-Package : No match was found …
Run Code Online (Sandbox Code Playgroud)

powershell package-managers powershellget

4
推荐指数
1
解决办法
2323
查看次数

在VSTS托管代理上使用PowerShellGet

我在构建过程中使用的是Visual Studio Team Services(VSTS)托管的构建代理。我的构建主要依赖于“ PowerShell”步骤,该步骤调用了我在git中拥有的脚本。在此脚本中,我想使用PowerShellGet管理PowerShell模块。例如,我希望能够仅通过运行以下命令来安装pscx

Install-Module -Name pscx
Run Code Online (Sandbox Code Playgroud)

不幸的是,托管代理使用PowerShell 4,并且没有PowerShellGet安装模块。结果,该Install-Module功能不可用。

有人建议在VSTS托管代理上使用PowerShellGet模块吗?请注意,由于我在这台计算机上没有管理员权限,因此无法安装为PowerShell 4安装PowerShellGet的msi。

powershellget azure-devops azure-pipelines-build-task azure-pipelines

3
推荐指数
1
解决办法
1026
查看次数

Register-PsRepository : 在此对象上找不到属性“名称”

尝试运行 Register-PsRepository 时出现以下错误

我试过了:

  • 重新安装 WMF 5、PowerShellGet 和 PackageManagement 模块
  • 更新所述模块
  • 调试 PowerShellGet 模块我可以看到 PsBoundParameters 确实将 Name 值传递给 Register-PackageSource 命令。
  • 当我手动运行 Register-PackageSource 时,它​​确实可以正常工作。

有任何想法吗?

PS C:\> Register-PSRepository -Name MyRepo -SourceLocation  https://MyRepo.com/api/Myrepo   -Credential $c
PackageManagement\Register-PackageSource : The property 'Name' cannot be 
found on this object. Verify that the property exists.
At C:\Program  Files\WindowsPowerShell\Modules\PowerShellGet\1.6.0\PSModule.psm1:4631 char:17
Run Code Online (Sandbox Code Playgroud)

powershell powershellget

3
推荐指数
1
解决办法
1752
查看次数