$path = "C:\apps\develop\sdks\python"$content = " Usage: pvm help show the usage of pvm pvm using show the python version in use pvm list show all version pvm use <version> switch version"function ListVersion { # 将前缀是v的文件过滤出来 Get-Item ($path + "\v*") | ForEach-Object { $_.Name }}function UseVersion ($version ) { $arguments = "New-Item -ItemType SymbolicLink -Path '$path\current' -Target '$path\$version' -Force" $user = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() if (-NOT ($user).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell -Verb runAs -ArgumentList $arguments return } # Invoke-Expression 将字符串解析成命令执行 Invoke-Expression $arguments}switch ($args[0]) { "help" { $content } "using" { if (-not (Test-Path "$path\current")) { Write-Host "Please execute the use command first" exit } python --version } "list" { ListVersion } "use" { if ($null -eq $args[1]) { $content exit } $version = $args[1].ToString().ToLower(); if (-not $version.StartsWith("v")) { $version = "v$version" } if ((ListVersion) -contains $version) { UseVersion $version } else { Write-Host "No matching version" } } Default { $content }}