我的巧克力脚本的代码:
$apps=@('googlechrome','firefox','codeblocks','windbg','nasm','explorersuite','pestudio','vscode','sysinternals','python','Google Earth')
function Show-Menu
{
Clear-Host
Write-Host "**********************************************"
Write-Host "LIST OF SOFTWARES"
# write the options using the array of packages
for ($i = 0; $i -lt $apps.Count; $i++)
{
# {0,5} means right align with spaces to max 5 characters
Write-Host ('{0,5}. {1}' -f ($i + 1), $apps[$i])
}
Write-Host " q. Exit the script"
Write-Host "*************************************************"
Write-Host
}
# Step 4) enter an endless loop you only exit if the user enters 'q'
while ($true)
{
Show-Menu
$UserInput = Read-Host "Enter the software number to be installed"
# test if the user wants to quit and if so, break the loop
if ($UserInput -eq 'q')
{
break
}
# testing if the user entered a number between 1 and the total number of packages (inclusive)
if ([int]::TryParse($UserInput,[ref]$null) -and 1..$apps.Count -contains [int]$UserInput)
{
# here you install the chosen package using the array index number (= user input number minus 1)
$apps = [int]$UserInput - 1
foreach($app in $apps)
{
$result = Get-InstalledApps | Where-Object { $_.DisplayName -like $app }
if($result -eq $null)
{
# get the index for the installer for this app
$i = $apps.IndexOf($app)
Write-Host "$app not found. Installing" $name[$i]
(cinst $name[$i] -y)
}
else
{
$availableOptions = 1..$apps.Count -join ','
Write-Host "Error in selection, choose $availableOptions or q" -Foreground Color Red
}
$null = Read-Host "Press Enter to continue"
}
}
}
当我运行脚本时收到以下错误消息:
Enter the software number to be installed: 11
LIST OF SOFTWARES
1. googlechrome
2. firefox
3. codeblocks
4. windbg
5. nasm
6. explorersuite
7. pestudio
8. vscode
9. sysinternals
10. python
11. Google Earth
q. Exit the script
*************************************************
Enter the software number to be installed: 11
googlechrome not found. Installing googleearthpro
Chocolatey v0.11.1
Installing the following packages:
googleearthpro
By installing, you accept licenses for the packages.
googleearthpro v7.3.4 already installed.
Use --force to reinstall, specify a version to install, or try upgrade.
Chocolatey installed 0/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Warnings:
- googleearthpro - googleearthpro v7.3.4 already installed.
Use --force to reinstall, specify a version to install, or try upgrade.
Press Enter to continue:
firefox not found. Installing googlechrome
Chocolatey v0.11.1
Installing the following packages:
googlechrome
By installing, you accept licenses for the packages.
GoogleChrome v93.0.4577.63 already installed.
Use --force to reinstall, specify a version to install, or try upgrade.
Chocolatey installed 0/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Warnings:
- googlechrome - GoogleChrome v93.0.4577.63 already installed.
Use --force to reinstall, specify a version to install, or try upgrade.
Press Enter to continue:
codeblocks not found. Installing firefox
Chocolatey v0.11.1
Installing the following packages:
firefox
By installing, you accept licenses for the packages.
Firefox v91.0.2 already installed.
Use --force to reinstall, specify a version to install, or try upgrade.
Chocolatey installed 0/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Warnings:
- firefox - Firefox v91.0.2 already installed.
Use --force to reinstall, specify a version to install, or try upgrade.
Press Enter to continue:
windbg not found. Installing notepadplus
Chocolatey v0.11.1
Installing the following packages:
notepadplus
By installing, you accept licenses for the packages.
notepadplus not installed. The package was not found with the source(s) listed.
Source(s): 'https://community.chocolatey.org/api/v2/'
NOTE: When you specify explicit sources, it overrides default sources.
If the package version is a prerelease and you didn't specify `--pre`,
the package may not be found.
Please see https://docs.chocolatey.org/en-us/troubleshooting for more
assistance.
Chocolatey installed 0/1 packages. 1 packages failed.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Failures
- notepadplus - notepadplus not installed. The package was not found with the source(s) listed.
Source(s): 'https://community.chocolatey.org/api/v2/'
NOTE: When you specify explicit sources, it overrides default sources.
If the package version is a prerelease and you didn't specify `--pre`,
the package may not be found.
Please see https://docs.chocolatey.org/en-us/troubleshooting for more
assistance.
Press Enter to continue:
需要修复什么才能使其正常工作?
答案1
目前您问题中唯一的错误是notepadplus
安装失败,原因是:
The package was not found with the source(s) listed. Source(s): 'https://community.chocolatey.org/api/v2/'
您可能想要安装notepadplusplus
?