卸载阿里云CLI

卸载阿里云CLI

脚本示例

# Uninstall-CLI-Windows.ps1

# Purpose: Automatically detect and uninstall Aliyun CLI, and delete configuration files in user directory

[CmdletBinding()]

param (

[switch]$Clean,

[switch]$Help

)

function Show-Usage {

Write-Output @"

Alibaba Cloud Command Line Interface Uninstaller

-Help Display this help and exit

-Clean Remove user config file

"@

}

function Remove-DirectoryIfEmpty {

param([string]$Path)

if ((Get-ChildItem -Path $Path -Force).Count -eq 0) {

Remove-Item -Path $Path -Force

}

}

function Remove-AliyunCLIFromPath {

param([string]$PathToRemove)

$Key = 'HKCU:\Environment'

$CurrentPath = (Get-ItemProperty -Path $Key -Name PATH).PATH

if ($CurrentPath -like "*$PathToRemove*") {

$newPath = ($CurrentPath -split ';' | Where-Object { $_ -ne $PathToRemove }) -join ';'

Set-ItemProperty -Path $Key -Name PATH -Value $newPath

$env:PATH = $newPath

}

}

function Remove-AliyunCLI {

$AliyunBinary = (Get-Command aliyun -ErrorAction SilentlyContinue).Source

if ($AliyunBinary -and (Test-Path $AliyunBinary)) {

Remove-Item -Path $AliyunBinary -Force

$AliyunInstallDir = Split-Path -Parent $AliyunBinary

Remove-DirectoryIfEmpty -Path $AliyunInstallDir

Remove-AliyunCLIFromPath -PathToRemove $AliyunInstallDir

Write-Output "Aliyun CLI binary has been removed."

}

}

function Remove-ConfigFile {

$ConfigDir = Join-Path $HOME ".aliyun"

$ConfigFile = Join-Path $ConfigDir "config.json"

if (Test-Path $ConfigFile) {

Remove-Item -Path $ConfigFile -Force

Remove-DirectoryIfEmpty -Path $ConfigDir

Write-Output "Aliyun CLI config file has been removed."

}

}

if ($PSBoundParameters['Help']) {

Show-Usage

exit 0

}

Write-Output @"

..............888888888888888888888 ........=8888888888888888888D=..............

...........88888888888888888888888 ..........D8888888888888888888888I...........

.........,8888888888888ZI: ...........................=Z88D8888888888D..........

.........+88888888 ..........................................88888888D..........

.........+88888888 .......Welcome to use Alibaba Cloud.......O8888888D..........

.........+88888888 ............. ************* ..............O8888888D..........

.........+88888888 .... Command Line Interface(Reloaded) ....O8888888D..........

.........+88888888...........................................88888888D..........

..........D888888888888DO+. ..........................?ND888888888888D..........

...........O8888888888888888888888...........D8888888888888888888888=...........

............ .:D8888888888888888888.........78888888888888888888O ..............

"@

try {

Remove-AliyunCLI

if ($PSBoundParameters['Clean']) { Remove-ConfigFile }

Write-Output "Aliyun CLI has been uninstalled."

} catch {

Write-Output "Failed to uninstall Aliyun CLI: $_"

}

相关文章

京东除了618还有什么时候有活动?京东618什么时候最便宜
365bet官网网址多少

京东除了618还有什么时候有活动?京东618什么时候最便宜

⌛ 08-12 👁️‍🗨️ 3935
视频剪辑的三十个技巧:手把手教你从小白变接单大佬
365bet网址多少

视频剪辑的三十个技巧:手把手教你从小白变接单大佬

⌛ 09-22 👁️‍🗨️ 7243
扑街什么意思(大家都误会了!原来广东人讲“扑街”,并非真的骂人?)
完整指南:如何将文件从 iPhone 传输到 PC
365bet网址多少

完整指南:如何将文件从 iPhone 传输到 PC

⌛ 08-25 👁️‍🗨️ 6527
红雀手游
365bet官网网址多少

红雀手游

⌛ 09-27 👁️‍🗨️ 3980
京东华硕RTX3080被指耍猴,数十万人预定,只有20个评论
365bet官网网址多少

京东华硕RTX3080被指耍猴,数十万人预定,只有20个评论

⌛ 09-09 👁️‍🗨️ 4537