Поделиться через


Install-Script

Installs a script.

Синтаксис

NameParameterSet (по умолчанию)

Install-Script
    [-Name] <String[]>
    [-MinimumVersion <String>]
    [-MaximumVersion <String>]
    [-RequiredVersion <String>]
    [-Repository <String[]>]
    [-Scope <String>]
    [-NoPathUpdate]
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-Credential <PSCredential>]
    [-Force]
    [-AllowPrerelease]
    [-AcceptLicense]
    [-PassThru]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

InputObject

Install-Script
    [-InputObject] <PSObject[]>
    [-Scope <String>]
    [-NoPathUpdate]
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-Credential <PSCredential>]
    [-Force]
    [-AcceptLicense]
    [-PassThru]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Описание

The Install-Script cmdlet acquires a script payload from a repository, verifies that the payload is a valid PowerShell script, and copies the script file to a specified installation location.

This is a proxy cmdlet for the Install-PSResource cmdlet in the Microsoft.PowerShell.PSResourceGet. For more information, see Install-PSResource.

Примеры

Example 1: Find a script and install it

PS C:\> Find-Script -Repository "Local1" -Name "Required-Script2"
Version    Name                           Type       Repository           Description
-------    ----                           ----       ----------           -----------
2.5        Required-Script2               Script     local1               Description for the Required-Script2 script

PS C:\> Find-Script -Repository "Local1" -Name "Required-Script2" | Install-Script
PS C:\> Get-Command -Name "Required-Script2"
CommandType     Name                      Version    Source
-----------     ----                      -------    ------
ExternalScript  Required-Script2.ps1      2.0       C:\Users\pattif\Documents\WindowsPowerShell\Scripts\Required-Script2.ps1

PS C:\> Get-InstalledScript -Name "Required-Script2"
Version    Name                  Type     Repository           Description
-------    ----                  ----     ----------           -----------
2.5        Required-Script2      Script   local1               Description for the Required-Script2 script

PS C:\> Get-InstalledScript -Name "Required-Script2" | Format-List *
Name                       : Required-Script2
Version                    : 2.5
Type                       : Script
Description                : Description for the Required-Script2 script
Author                     : pattif
CompanyName                :
Copyright                  : 2015 Microsoft Corporation. All rights reserved.
PublishedDate              : 8/15/2015 12:42:39 AM
LicenseUri                 : http://required-script2.com/license
ProjectUri                 : http://required-script2.com/
IconUri                    : http://required-script2.com/icon
Tags                       : {Tag1, Tag2, Tag-Required-Script2-2.5, PSScript...}
Includes                   : {Function, DscResource, Cmdlet, Command}
PowerShellGetFormatVersion :
ReleaseNotes               : Required-Script2 release notes
Dependencies               : {}
RepositorySourceLocation   : http://pattif-dev:8765/api/v2/
Repository                 : local1
PackageManagementProvider  : NuGet
InstalledLocation          : C:\Users\pattif\Documents\WindowsPowerShell\Scripts

The first command finds the script named Required-Script2 from the Local1 repository and displays the results.

The second command finds the Required-Script2 script, and then uses the pipeline operator to pass it to the Install-Script cmdlet to install it.

The third command uses the Get-Command cmdlet to get Required-Script2, and then displays the results.

The fourth command uses the Get-InstalledScript cmdlet to get Required-Script2 and display the results.

The fifth command gets Required-Script2 and uses the pipeline operator to pass it to the Format-List cmdlet to format the output.

Example 2: Install a script with AllUsers scope

PS C:\> Install-Script -Repository "Local1" -Name "Required-Script3" -Scope "AllUsers"
PS C:\> Get-InstalledScript -Name "Required-Script3"
Version    Name                  Type       Repository    Description
-------    ----                  ----       ----------    -----------
2.5        Required-Script3      Script     local1        Description for the Required-Script3 script

PS C:\> Get-InstalledScript -Name "Required-Script3" | Format-List *
Name                       : Required-Script3
Version                    : 2.5
Type                       : Script
Description                : Description for the Required-Script3 script
Author                     : pattif
CompanyName                :
Copyright                  : 2015 Microsoft Corporation. All rights reserved.
PublishedDate              : 8/15/2015 12:42:45 AM
LicenseUri                 : http://required-script3.com/license
ProjectUri                 : http://required-script3.com/
IconUri                    : http://required-script3.com/icon
Tags                       : {Tag1, Tag2, Tag-Required-Script3-2.5, PSScript...}
Includes                   : {Function, DscResource, Cmdlet, Command}
PowerShellGetFormatVersion :
ReleaseNotes               : Required-Script3 release notes
Dependencies               : {}
RepositorySourceLocation   : http://pattif-dev:8765/api/v2/
Repository                 : local1
PackageManagementProvider  : NuGet
InstalledLocation          : C:\Program Files\WindowsPowerShell\Scripts

The first command installs the script named Required-Script3 and assigns it AllUsers scope.

The second command gets the installed script Required-Script3 and displays information about it.

The third command gets Required-Script3 and uses the pipeline operator to pass it to the Format-List cmdlet to format the output.

Example 3: Install a script and its dependencies

PS C:\> Find-Script -Repository "Local1" -Name "Script-WithDependencies2" -IncludeDependencies
Version    Name                        Type       Repository    Description
-------    ----                        ----       ----------    -----------
2.0        Script-WithDependencies2    Script     local1        Description for the Script-WithDependencies2 script
2.5        RequiredModule1             Module     local1        RequiredModule1 module
2.5        RequiredModule2             Module     local1        RequiredModule2 module
2.5        RequiredModule3             Module     local1        RequiredModule3 module
2.5        Required-Script1            Script     local1        Description for the Required-Script1 script
2.5        Required-Script2            Script     local1        Description for the Required-Script2 script
2.5        Required-Script3            Script     local1        Description for the Required-Script3 script

PS C:\> Install-Script -Repository "Local1" -Name "Script-WithDependencies2"
PS C:\> Get-InstalledScript
Version    Name                        Type       Repository    Description
-------    ----                        ----       ----------    -----------
2.5        Required-Script1            Script     local1        Description for the Required-Script1 script
2.5        Required-Script2            Script     local1        Description for the Required-Script2 script
2.5        Required-Script3            Script     local1        Description for the Required-Script3 script
2.0        Script-WithDependencies2    Script     local1        Description for the Script-WithDependencies2 script

PS C:\> Get-InstalledModule
Version    Name                        Type       Repository    Description
-------    ----                        ----       ----------    -----------
2.5        RequiredModule1             Module     local1        RequiredModule1 module
2.5        RequiredModule2             Module     local1        RequiredModule2 module
2.5        RequiredModule3             Module     local1        RequiredModule3 module

PS C:\> Find-Script -Repository "Local1" -Name "Required-Script*"
Version    Name                        Type       Repository    Description
-------    ----                        ----       ----------    -----------
2.5        Required-Script1            Script     local1        Description for the Required-Script1 script
2.5        Required-Script2            Script     local1        Description for the Required-Script2 script
2.5        Required-Script3            Script     local1        Description for the Required-Script3 script

PS C:\> Install-Script -Repository "Local1" -Name "Required-Script*"
PS C:\> Get-InstalledScript
Version    Name                        Type       Repository    Description
-------    ----                        ----       ----------    -----------
2.5        Required-Script1            Script     local1        Description for the Required-Script1 script
2.5        Required-Script2            Script     local1        Description for the Required-Script2 script
2.5        Required-Script3            Script     local1        Description for the Required-Script3 script

The first command finds the script named Script-WithDependencies2 and its dependencies in the Local1 repository and displays the results.

The second command installs Script-WithDependencies2.

The third command uses the Get-InstalledScript script cmdlet to get installed scripts and display the results.

The fourth command uses the Get-InstalledModule cmdlet to get installed modules and display the results.

The fifth command uses the Find-Script cmdlet to find scripts where the name begins with Required-Script and display the results.

The sixth command installs the scripts where the name begins with Required-Script in the Local1 repository.

The final command gets installed scripts and displays the results.

Параметры

-AcceptLicense

Automatically accept the license agreement during installation if the module requires it.

Свойства параметра

Тип:SwitchParameter
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-AllowPrerelease

Allows you to install a script marked as a prerelease.

The proxy cmdlet maps this parameter to the Prerelease parameter of Install-PSResource.

Свойства параметра

Тип:SwitchParameter
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

NameParameterSet
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Свойства параметра

Тип:SwitchParameter
Default value:False
Поддерживаются подстановочные знаки:False
DontShow:False
Aliases:cf

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-Credential

Specifies a user account that has rights to install a script for a specified package provider or source.

Свойства параметра

Тип:PSCredential
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:True
Значение из оставшихся аргументов:False

-Force

The proxy cmdlet ignores this parameter since it's not supported by Install-PSResource.

Свойства параметра

Тип:SwitchParameter
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-InputObject

Used for pipeline input. An error is thrown if a value supplied directly to InputObject. Use the pipeline to pass objects with the InputObject parameter.

Свойства параметра

Тип:

PSObject[]

Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

InputObject
Position:0
Обязательно:True
Значение из конвейера:True
Значение из конвейера по имени свойства:True
Значение из оставшихся аргументов:False

-MaximumVersion

The proxy cmdlet uses the value of this parameter to create a NuGet version search string for use with the Version parameter of Install-PSResource.

Свойства параметра

Тип:String
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

NameParameterSet
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:True
Значение из оставшихся аргументов:False

-MinimumVersion

The proxy cmdlet uses the value of this parameter to create a NuGet version search string for use with the Version parameter of Install-PSResource.

Свойства параметра

Тип:String
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

NameParameterSet
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:True
Значение из оставшихся аргументов:False

-Name

Specifies an array of names of scripts to install.

Свойства параметра

Тип:

String[]

Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

NameParameterSet
Position:0
Обязательно:True
Значение из конвейера:False
Значение из конвейера по имени свойства:True
Значение из оставшихся аргументов:False

-NoPathUpdate

The proxy cmdlet ignores this parameter since it's not supported by Install-PSResource.

Свойства параметра

Тип:SwitchParameter
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-PassThru

When using the PassThru parameter, Install-Script outputs a PSRepositoryItemInfo object for the module. This is the same information that you get from the Find-Script cmdlet.

Свойства параметра

Тип:SwitchParameter
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-Proxy

The proxy cmdlet ignores this parameter since it's not supported by Install-PSResource.

Свойства параметра

Тип:Uri
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:True
Значение из оставшихся аргументов:False

-ProxyCredential

The proxy cmdlet ignores this parameter since it's not supported by Install-PSResource.

Свойства параметра

Тип:PSCredential
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:True
Значение из оставшихся аргументов:False

-Repository

Specifies the friendly name of a repository that has been registered with the Register-PSRepository cmdlet. The default is all registered repositories.

Свойства параметра

Тип:

String[]

Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

NameParameterSet
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-RequiredVersion

The proxy cmdlet uses the value of this parameter to create a NuGet version search string for use with the Version parameter of Install-PSResource.

Свойства параметра

Тип:String
Default value:None
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

NameParameterSet
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:True
Значение из оставшихся аргументов:False

-Scope

Specifies the installation scope of the script. Valid values are: AllUsers and CurrentUser.

The AllUsers scope lets modules be installed in a location that is accessible to all users of the computer, that is, $env:ProgramFiles\WindowsPowerShell\Scripts.

The CurrentUser scope lets modules be installed only to $HOME\Documents\WindowsPowerShell\Scripts, so that the module is available only to the current user.

When no Scope is defined, the default will be set based on the current session:

  • For an elevated PowerShell session, Scope defaults to AllUsers;
  • For non-elevated PowerShell sessions in PowerShellGet versions 2.0.0 and above, Scope is CurrentUser;
  • For non-elevated PowerShell sessions in PowerShellGet versions 1.6.7 and earlier, Scope is undefined, and Install-Module fails.

Свойства параметра

Тип:String
Default value:None
Допустимые значения:CurrentUser, AllUsers
Поддерживаются подстановочные знаки:False
DontShow:False

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Свойства параметра

Тип:SwitchParameter
Default value:False
Поддерживаются подстановочные знаки:False
DontShow:False
Aliases:wi

Наборы параметров

(All)
Position:Named
Обязательно:False
Значение из конвейера:False
Значение из конвейера по имени свойства:False
Значение из оставшихся аргументов:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Входные данные

String

PSObject

String

Uri

PSCredential

Выходные данные

Object

Примечания

Important

As of April 2020, the PowerShell Gallery no longer supports Transport Layer Security (TLS) versions 1.0 and 1.1. If you are not using TLS 1.2 or higher, you will receive an error when trying to access the PowerShell Gallery. Use the following command to ensure you are using TLS 1.2:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

For more information, see the announcement in the PowerShell blog.