Fix-PSResourceRepository.ps1
|
# Fix PSResourceGet Repository Configuration Write-Host "Fixing PSResourceGet repository configuration..." -ForegroundColor Cyan Write-Host "" # Create the directory if it doesn't exist $psResourceGetPath = Join-Path $env:LOCALAPPDATA "PSResourceGet" $repoFile = Join-Path $psResourceGetPath "PSResourceRepository.xml" Write-Host "Creating directory: $psResourceGetPath" -ForegroundColor Yellow if (-not (Test-Path $psResourceGetPath)) { New-Item -ItemType Directory -Path $psResourceGetPath -Force | Out-Null Write-Host "Directory created." -ForegroundColor Green } else { Write-Host "Directory already exists." -ForegroundColor Green } Write-Host "" # Register PSGallery for PSResourceGet Write-Host "Registering PSGallery repository..." -ForegroundColor Yellow try { # Check if command exists if (Get-Command Register-PSResourceRepository -ErrorAction SilentlyContinue) { Register-PSResourceRepository -PSGallery -ErrorAction SilentlyContinue Write-Host "PSGallery registered successfully!" -ForegroundColor Green } else { Write-Host "PSResourceGet module not found. Installing..." -ForegroundColor Yellow Install-Module -Name Microsoft.PowerShell.PSResourceGet -Force -AllowClobber -Scope CurrentUser Import-Module Microsoft.PowerShell.PSResourceGet -Force Register-PSResourceRepository -PSGallery Write-Host "PSResourceGet installed and PSGallery registered!" -ForegroundColor Green } } catch { Write-Host "Note: $($_.Exception.Message)" -ForegroundColor Yellow } Write-Host "" Write-Host "========================================" -ForegroundColor Cyan Write-Host "Configuration complete!" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Cyan Write-Host "" Write-Host "You can now use either:" -ForegroundColor Yellow Write-Host " 1. Publish-Module (PowerShellGet 2.x)" -ForegroundColor White Write-Host " 2. Publish-PSResource (PSResourceGet 3.x)" -ForegroundColor White Write-Host "" |