概要
某些模組發行者的法律部門要求客戶必須先明確接受授權,才能從 PowerShell 資源庫安裝其模組。 如果使用者使用 PowerShellGet 安裝、更新或儲存模組,無論是直接安裝或作為另一個套件的相依性,而且該模組需要使用者同意授權,使用者必須指出他們接受授權,否則作業會失敗。
發佈模組的需求
想要要求使用者接受授權的模組應滿足以下要求:
- 模組資訊清單的 PSData 區段應該包含 RequireLicenseAcceptance = $True。
- 模組應該在根目錄中包含 license.txt 檔案。
- 模組資訊清單應包含授權 Uri。
- 模組應該使用 PowerShellGet 格式 2.0 版和更新版本發佈。
對安裝/儲存/Update-Module 的影響
- 安裝/儲存/更新 Cmdlet 支援新的參數 AcceptLicense ,其行為就像使用者看到授權一樣。
- 如果 RequiredLicenseAcceptance 為 True 且未指定 AcceptLicense ,則會顯示
license.txt使用者 ,並提示使用者:Do you accept these license terms (Yes/No/YesToAll/NoToAll)。- 如果接受授權
- Save-Module: 將模組複製到使用者的系統
- Install-Module: 模組會複製到使用者系統到適當的資料夾(根據範圍)
- Update-Module: 模組已更新。
- 如果許可證被拒絕。
- 作業已取消。
- 所有 Cmdlet 都會檢查中繼資料 (requireLicenseAcceptance 和 Format Version) ,指出需要接受授權
- 如果用戶端的格式化版本早於 2.0,則作業會失敗,並要求使用者更新用戶端。
- 如果模組以早於 2.0 的格式版本發佈,則會忽略 requireLicenseAcceptance 旗標。
- 如果接受授權
模組相依性
- 在安裝/儲存/更新作業期間,如果相依模組 (其他專案取決於模組) 需要授權接受,則需要授權接受行為 (上述)。
- 如果模組版本已在本機型錄中列為已安裝在系統上,我們將略過授權檢查。
- 在安裝/儲存/更新作業期間,如果相依模組需要授權,且未接受授權,則作業會失敗,並遵循無法安裝/儲存/更新套件的正常程序。
對 -Force 的影響
指定 –Force 不足以接受授權。
–AcceptLicense 需要安裝權限。 如果指定,則 –Force RequiredLicenseAcceptance 為 True,且 –AcceptLicense 未指定,則作業會失敗。
例子
範例 1:更新模組資訊清單以要求接受授權
Update-ModuleManifest -Path C:\modulemanifest.psd1 -RequireLicenseAcceptance -PrivateData @{
PSData = @{
# Flag to indicate whether the module requires explicit user acceptance
RequireLicenseAcceptance = $true
} # End of PSData hashtable
} # End of PrivateData hashtable
此命令會更新資訊清單檔案,並將 RequireLicenseAcceptance 旗標設定為 true。
範例 2:安裝需要接受授權的模組
Install-Module -Name ModuleRequireLicenseAcceptance
License Acceptance
License 2.0
Copyright (c) 2016 PowerShell Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software.
Do you accept the license terms for module 'ModuleRequireLicenseAcceptance'.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
此命令顯示檔案中的 license.txt 許可證,並提示使用者接受許可證。
範例 3:安裝模組,需要使用 -AcceptLicense 接受授權
Install-Module -Name ModuleRequireLicenseAcceptance -AcceptLicense
安裝模組時沒有任何接受授權的提示。
範例 4:安裝模組,需要接受授權和 -Force
Install-Module -Name ModuleRequireLicenseAcceptance -Force
PackageManagement\Install-Package : License Acceptance is required for module 'ModuleRequireLicenseAcceptance'. Please specify '-AcceptLicense' to perform this operation.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.1.3.3\PSModule.psm1:1837 char:21
+ ... $null = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], E
xception
+ FullyQualifiedErrorId : ForceAcceptLicense,Install-PackageUtility,Microsoft.PowerShell.PackageManagement.Cmdlets
.InstallPackage
範例 5:安裝具有需要接受授權的相依性模組
模組 ModuleWithDependency 相依於模組 ModuleRequireLicenseAcceptance。 系統會提示使用者接受授權。
Install-Module -Name ModuleWithDependency
License Acceptance
MIT License 2.0
Copyright (c) 2016 PowerShell Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software.
Do you accept the license terms for module 'ModuleRequireLicenseAcceptance'.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
範例 6:安裝具有需要授權接受和 -AcceptLicense 的相依性模組
模組 ModuleWithDependency 相依於模組 ModuleRequireLicenseAcceptance。 系統不會提示使用者接受授權,因為指定了 AcceptLicense 。
Install-Module -Name ModuleWithDependency -AcceptLicense
範例 7:在早於 PSGetFormatVersion 2.0 的用戶端上安裝需要接受授權的模組
Install-Module -Name ModuleRequireLicenseAcceptance
WARNING: The specified module 'ModuleRequireLicenseAcceptance' with PowerShellGetFormatVersion
'2.0' is not supported by the current version of PowerShellGet. Get the latest version of the
PowerShellGet module to install this module, 'ModuleRequireLicenseAcceptance'.
範例 8:需要接受授權的儲存模組
Save-Module -Name ModuleRequireLicenseAcceptance -Path C:\Saved
License Acceptance
License 2.0
Copyright (c) 2016 PowerShell Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software.
Do you accept the license terms for module 'ModuleRequireLicenseAcceptance'.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
此命令顯示檔案中的 license.txt 許可證,並提示使用者接受許可證。
範例 9:儲存模組,需要使用 -AcceptLicense 接受授權
Save-Module -Name ModuleRequireLicenseAcceptance -AcceptLicense -Path C:\Saved
模組會儲存,而不會提示接受授權。
範例 10:需要接受授權的更新模組
Update-Module -Name ModuleRequireLicenseAcceptance
License Acceptance
License 2.0
Copyright (c) 2016 PowerShell Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software.
Do you accept the license terms for module 'ModuleRequireLicenseAcceptance'.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
此命令顯示檔案中的 license.txt 許可證,並提示使用者接受許可證。
範例 11:更新模組需要使用 -AcceptLicense 接受授權
Update-Module -Name ModuleRequireLicenseAcceptance -AcceptLicense
模組已更新,但沒有任何接受授權的提示。