forked from farag2/Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPublish-Module.ps1
63 lines (49 loc) · 1.54 KB
/
Publish-Module.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<#
.SYNOPSIS
Publish PowerShell module to PowerShell Gallery
.PARAMETER Path
Path to a module folder
.PARAMETER NuGetApiKey
Your API key got from PowerShell Gallery
.EXAMPLE
PublishModule -Path D:\folder -NuGetApiKey <APIKey>
#>
function PublishModule
{
param
(
[Parameter(Mandatory = $true)]
[String]
$Path,
[Parameter(Mandatory = $true)]
[String]
$NuGetApiKey
)
Clear-Host
# [Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding("Windows-1251")
if ($psISE)
{
exit
}
# Enable TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Automatically installs the NuGet provider if it isn't installed
Get-PackageProvider -Name NuGet -ForceBootstrap
if ($null -eq (Get-Module PowerShellGet -ListAvailable | Where-Object -FilterScript {$_.Version -eq "2.2.5"}))
{
Install-Module -Name PowerShellGet -RequiredVersion 2.2.5 -Force
}
else
{
Import-Module -Name PowerShellGet
}
if (-not (Test-Path -Path HKLM:\Software\Microsoft\.NetFramework\v4.8))
{
New-Item -Path HKLM:\Software\Microsoft\.NetFramework\v4.8 -Force
}
New-ItemProperty -Path HKLM:\Software\Microsoft\.NetFramework\v4.8 -Name SchUseStrongCrypto -Value 1 -PropertyType DWord -Force
# Publishing
Publish-Module -Path $Path -NuGetApiKey $NuGetApiKey -Force -Verbose
Remove-Item -Path HKLM:\Software\Microsoft\.NetFramework\v4.8 -Force
}
PublishModule -Path "C:\Users\test\Desktop\Sophia" -NuGetApiKey oy2gxymm4xz75t7vwcna6q6fp7ubfi3upbbqwf4ebceyxu