@echo off

for /f "delims=" %%F in ('dir /b "%~dp0\NetAppDocs_package\NetAppDocs*.zip" 2^>nul') do set NetAppDocsPackageFile=%~dp0NetAppDocs_package\%%F

if not defined NetAppDocsPackageFile (
    echo NetAppDocs package file is not present. Unable to continue with install.
    exit
)

pwsh -NoProfile -NonInteractive -Command "exit" >nul 2>&1
if %errorlevel% == 0 ( goto :PSVersionChoice ) else ( goto :PS5 )

:PSVersionChoice
    echo.
    choice /C 75Q /T 10 /D 7 /N /M "Which version of PowerShell do you want to install this module to (press 5 for Windows PowerShell 5.1, 7 for PowerShell 7, Q to Quit)?"
    if %errorlevel% == %0 if %errorlevel% == 1 goto :PS7
    if %errorlevel% == 2 goto :PS5
    if %errorlevel% == 3 goto :end

:PS7
pwsh -NoProfile -ExecutionPolicy RemoteSigned -Command "& '%~dp0Install_Script\install.ps1' -ModulePackageFile '%NetAppDocsPackageFile%'"
goto :end

:PS5
powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -Command "& '%~dp0Install_Script\install.ps1' -ModulePackageFile '%NetAppDocsPackageFile%'"
goto :end

:end
exit /b 0
