Anteckning
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
SAMMANFATTNING
Juridiska avdelningar för vissa modulutgivare kräver att kunderna uttryckligen måste godkänna licensen innan de installerar modulen från PowerShell-galleriet. Om en användare installerar, uppdaterar eller sparar en modul med PowerShellGet, oavsett om det är direkt eller som ett beroende för ett annat paket, och modulen kräver att användaren godkänner en licens, måste användaren ange att de accepterar licensen, annars misslyckas åtgärden.
Publiceringskrav för moduler
Moduler som vill kräva att användarna accepterar licensen bör uppfylla följande krav:
- PSData-avsnittet i modulmanifestet ska innehålla RequireLicenseAcceptance = $True.
- Modulen ska innehålla license.txt fil i rotkatalogen.
- Modulmanifestet ska innehålla licens-URI.
- Modulen ska publiceras med PowerShellGet-format version 2.0 och senare.
Påverkan på Installera/Spara/Update-Module
- Cmdlets för att installera/spara/uppdatera stöder en ny parameter AcceptLicense som beter sig som om användaren såg licensen.
- Om RequiredLicenseAcceptance är True och AcceptLicense inte har angetts visas användaren och license.txtuppmanas att:Do you accept these license terms (Yes/No/YesToAll/NoToAll).- Om licensen accepteras - Save-Module: modulen kopieras till användarens system
- Install-Module: modulen kopieras till användarens system till rätt mapp (baserat på omfattning)
- Update-Module: modulen uppdateras.
 
- Om licensen nekas.
- Operationen avbryts.
- Alla cmdlets söker efter metadata (requireLicenseAcceptance och Format Version) som säger att ett licensgodkännande krävs
- Om formatversionen av klienten är äldre än 2.0 misslyckas åtgärden och användaren uppmanas att uppdatera klienten.
- Om modulen har publicerats med en formatversion som är äldre än 2.0 ignoreras flaggan requireLicenseAcception.
 
 
- Om licensen accepteras 
Modul Beroenden
- Om en beroende modul (något annat beror på modulen) kräver godkännande av licensen under installationen/spara/uppdateringen, krävs beteendet för licensgodkännande (ovan).
- Om modulversionen redan är listad i den lokala katalogen som installerad på systemet, skulle vi kringgå licenskontrollen.
- Om en beroende modul kräver en licens under installationen/spara/uppdateringen misslyckas åtgärden och följer normala processer för paketet kunde inte installeras/spara/uppdateras.
Påverkan på -Force
Det räcker INTE att ange –Force för att acceptera en licens. 
              –AcceptLicense krävs för behörighet att installera. Om –Force anges är RequiredLicenseAcceptance True och –AcceptLicense anges INTE misslyckas åtgärden.
EXEMPEL
Exempel 1: Uppdatera modulmanifestet för att kräva godkännande av licensen
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
Det här kommandot uppdaterar manifestfilen och anger flaggan RequireLicenseAcceptance till true.
Exempel 2: Installationsmodul som kräver godkännande av licensen
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"):
Det här kommandot visar licensen från license.txt filen och uppmanar användaren att acceptera licensen.
Exempel 3: Installera modul som kräver godkännande av licens med -AcceptLicense
Install-Module -Name ModuleRequireLicenseAcceptance -AcceptLicense
Modulen installeras utan någon uppmaning att acceptera licensen.
Exempel 4: Installationsmodul som kräver godkännande av licensen med -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
Exempel 5: Installera modul med beroenden som kräver godkännande av licens
Module ModuleWithDependency är beroende av modulen ModuleRequireLicenseAcceptance. Användaren uppmanas att acceptera licensen.
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"):
Exempel 6: Installera modulen med beroenden som kräver godkännande av licens och -AcceptLicense
Module ModuleWithDependency är beroende av modulen ModuleRequireLicenseAcceptance. Användaren uppmanas inte att acceptera licensen eftersom AcceptLicense har angetts.
Install-Module -Name ModuleWithDependency -AcceptLicense
Exempel 7: Installera modulen som kräver licensgodkännande på en klient som är äldre än 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'.
Exempel 8: Spara modul som kräver godkännande av licens
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"):
Det här kommandot visar licensen från license.txt filen och uppmanar användaren att acceptera licensen.
Exempel 9: Spara modul som kräver godkännande av licens med -AcceptLicense
Save-Module -Name ModuleRequireLicenseAcceptance -AcceptLicense -Path C:\Saved
Modulen sparas utan någon uppmaning om att acceptera licensen.
Exempel 10: Uppdateringsmodul som kräver godkännande av licens
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"):
Det här kommandot visar licensen från license.txt filen och uppmanar användaren att acceptera licensen.
Exempel 11: Uppdateringsmodul som kräver godkännande av licens med -AcceptLicense
Update-Module -Name ModuleRequireLicenseAcceptance -AcceptLicense
Modulen uppdateras utan att du uppmanas att acceptera licensen.
Mer information
Kräv licensgodkännande för skript
Kräv stöd för licensgodkännande på PowerShellGallery
Kräv godkännande av licens vid distribution till Azure Automation
PowerShell Gallery