nupkg 常用函数

最后更新于:2022-04-02 03:46:55

[TOC] ## Install-BinFile ``` Install-BinFile ` -Name ` -Path ` [-UseStart] ` [-Command ] ` [-IgnoredArguments ] [] ``` ## Install-ChocolateyDesktopLink ``` Install-ChocolateyDesktopLink ` -TargetFilePath ` [-IgnoredArguments ] [] ``` ## Install-ChocolateyEnvironmentVariable ``` Install-ChocolateyEnvironmentVariable ` [-VariableName ] ` [-VariableValue ] ` [-VariableType {Process | User | Machine}] ` [-IgnoredArguments ] [] ``` ## Install-ChocolateyPackage 根据远程文件下载,将软件安装到“程序和功能”中。当是本地文件或嵌入式文件时,请使用Install-ChocolateyInstallPackage。 ``` Install-ChocolateyPackage ` -PackageName ` [-FileType ] ` [-SilentArgs ] ` [-Url ] ` [-Url64bit ] ` [-ValidExitCodes ] ` [-Checksum ] ` [-ChecksumType ] ` [-Checksum64 ] ` [-ChecksumType64 ] ` [-Options ] ` [-File ] ` [-File64 ] ` [-UseOnlyPackageSilentArguments] ` [-UseOriginalLocation] ` [-IgnoredArguments ] [] ``` 实例 ``` $packageName= 'bob' $toolsDir = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)" $url = 'https://somewhere.com/file.msi' $url64 = 'https://somewhere.com/file-x64.msi' $packageArgs = @{ packageName = $packageName fileType = 'msi' url = $url url64bit = $url64 silentArgs = "/qn /norestart" validExitCodes= @(0, 3010, 1641) softwareName = 'Bob*' checksum = '12345' checksumType = 'sha256' checksum64 = '123356' checksumType64= 'sha256' } Install-ChocolateyPackage @packageArgs ``` ## Install-ChocolateyPath 目录添加到环境变量中 ``` Install-ChocolateyPath ` -PathToInstall ` [-PathType {Process | User | Machine}] ` [-IgnoredArguments ] [] ``` 实例 ``` Install-ChocolateyPath "$($env:SystemDrive)\Program Files\MySQL\MySQL Server 5.5\bin" -PathType 'Machine' ``` ## Install-ChocolateyWindowsService 使用Install Util安装Windows服务, ``` Install-ChocolateyWindowsService ` -Name ` -ServiceExecutablePath ` [-Username ] ` [-Password ] ` [-DisplayName ] ` [-Description ] ` [-StartupType {Unknown | Manual | Automatic | Disabled}] ` [-DoNotStartService] ` [-DoNotReinstallService] ` [] ``` 实例 ``` $toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" $serviceExe = Join-Path $toolsDir 'service\dan-agent.exe' $packageArgs = @{ Name = 'dan' DisplayName = 'Dan Agent' ServiceExecutablePath = $serviceExe Username = 'DanTheBuilder' } Install-ChocolateyWindowsService @packageArgs` ``` ## Install-ChocolateyZipPackage 安装压缩包 ``` Install-ChocolateyZipPackage ` -PackageName ` [-Url ] ` -UnzipLocation ` [-Url64bit ] ` [-SpecificFolder ] ` [-Checksum ] ` [-ChecksumType ] ` [-Checksum64 ] ` [-ChecksumType64 ] ` [-Options ] ` [-File ] ` [-File64 ] ` [-IgnoredArguments ] [] ``` 实例 ``` Install-ChocolateyZipPackage -PackageName 'sysinternals' ` -Url 'http://download.sysinternals.com/Files/SysinternalsSuite.zip' ` -UnzipLocation "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)" ` -Url64 'http://download.sysinternals.com/Files/SysinternalsSuitex64.zip' ``` ## Start-ChocolateyWindowsService 启动win 服务 ``` Start-ChocolateyWindowsService ` -Name ` [] ``` ## Stop-ChocolateyWindowsService ``` Stop-ChocolateyWindowsService ` -Name ` [] ``` ## Test-ProcessAdminRights 测试管理员权限 ``` Test-ProcessAdminRights ``` ## Uninstall-BinFile 移除命令 ``` Uninstall-BinFile ` -Name ` [-Path ] ` [-IgnoredArguments ] [] ``` ## Uninstall-ChocolateyEnvironmentVariable 移除环境变量 ``` Uninstall-ChocolateyEnvironmentVariable ` -VariableName ` [-VariableType {Process | User | Machine}] ` [-IgnoredArguments ] [] ``` 实例 ``` Uninstall-ChocolateyEnvironmentVariable -VariableName 'bob' ``` ## Uninstall-ChocolateyPackage ``` Uninstall-ChocolateyPackage ` -PackageName ` [-FileType ] ` [-SilentArgs ] ` [-File ] ` [-ValidExitCodes ] ` [-IgnoredArguments ] [] ``` 实例 ``` Uninstall-ChocolateyPackage -PackageName $packageName ` -FileType $installerType ` -SilentArgs "$silentArgs" ` -ValidExitCodes $validExitCodes ` -File "$file" ``` ## Uninstall-ChocolateyWindowsService ``` Uninstall-ChocolateyWindowsService ` -Name ` [] ``` ## Uninstall-ChocolateyZipPackage ``` Uninstall-ChocolateyZipPackage ` -PackageName ` -ZipFileName ` [-IgnoredArguments ] [] ``` 实例 ``` Uninstall-ChocolateyZipPackage '__NAME__' 'filename.zip' ``` ## Update-SessionEnvironment 使用Chocolatey软件包安装过程中发生的任何环境变量更改来更新当前Powershell会话的环境变量。 ``` Update-SessionEnvironment ``` ';