OK, this problem might NOT
be directly connected to PowerShell, although an answer to my above question would be nice.
After a LOT of time troubleshooting, I have narrowed the weird behaviour down to TWO echo.
in the code.
Here is the test file. If you run the code you will see what I mean. I have quoted the TWO lines and the operation needed to make it work . . .
Code:
@echo off
if not "%1"=="max" start /max cmd /c %0 max & exit /b
setlocal EnableDelayedExpansion
set "Params=%*"
cd /d "%~dp0" && ( if exist "%Temp%\getadmin.vbs" del "%Temp%\getadmin.vbs") && fsutil dirty query %SystemDrive% 1>nul 2>nul || ( echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %Params%", "", "runas", 1 >> "%Temp%\getadmin.vbs" && "%Temp%\getadmin.vbs" && Exit /b)
%windir%\system32\reg.exe query "HKU\S-1-5-19" 1>nul 2>nul || ( echo. & echo ERROR: This Batch file MUST be run in an ELEVATED cmd prompt [ Administrator ] & echo. & echo Right-click the Batch file and click ^<Run as Administrator^>. & echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit )
set "DT=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
for /f "usebackq tokens=3" %%X in (`Reg Query "%DT%" /V Desktop`) do (set Desktop=%%X)
for /f "usebackq delims=" %%X in (`echo "%Desktop%"`) do (set "Desktop=%%X")
set "Desktop=%Desktop:~1,-1%"
Set "Folder_Name=Sys_Reports"
set "DT_Folder=%Desktop%\%Folder_Name%"
set "LOG_01=Appx_Packages_Current_User"
:Options
set "Input= "
echo. & echo ======================================================================================================================================================================
echo some info here
echo ======================================================================================================================================================================
echo. & echo IF YOU TAKE OUT THE echo. AND LEAVE JUST THE echo ON THIS LINE AND THE NEXT IT WORKS
echo. & echo ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
echo some info here
echo ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
echo 0. EXIT this Program
echo 1.
echo 2.
echo 3.
echo 4.
echo 5.
echo 6.
echo 7.
echo 8
echo 9
echo 10.
echo 11.
echo 12.
echo 13.
echo 14.
echo 15.
echo 16.
echo 17.
echo 18.
echo 19.
echo 20.
echo 21.
echo 23.
echo 24.
echo 25.
echo 26.
echo 27.
echo 28.
echo 29.
echo 30.
echo 31.
echo 32.
echo 33.
echo 34.
echo 35.
echo 36.
echo 37.
echo 38.
echo 39.
echo 40.
echo ======================================================================================================================================================================&echo.
set "Input="
set /P "Input=>Enter an Option and press <Enter>: "
if "%Input%"=="" cls & goto :Options
if /i %Input%==0 Exit
if /i %Input%==1 goto :AppxPackages_Current
goto :Options
:AppxPackages_Current
set "Title=Appx Packages - Current User"
set "LOG=Appx_Packages_Current_User.log"
set "OFN=%DT_Folder%\%LOG%"
if not exist %DT_Folder% (mkdir %DT_Folder% >nul 2>&1)
if exist %OFN% (del /f /q %OFN% >nul 2>&1)
echo. & echo Processing . . .
>> %OFN% echo ============================================================================= START ==================================================================================
PowerShell $Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size(250,250)
>> %OFN% PowerShell Get-AppxPackage -User %UserName% ^| Sort-Object -Property Name ^| Select Name, PackageFullName, Publisher, PublisherId, ResourceID ^| Format-Table
>> %OFN% echo ============================================================================== EOF ===================================================================================
echo Processing Complete.
echo. & echo ^>Press ANY key to return to the Options . . . & pause >nul & cls & goto :Options
AFTER you have run Option 1
, if you scroll down, you will see an EXTRA
>Enter an Option and press <Enter>:
. As you scroll down further, it remains the last line on the screen.
I wonder if it is ME, or if there really is a problem!
I am NOT
interested in adapting or modifying the code, just WHY this is an issue please.
Thanks.
EDIT:
I have just run this on another computer and it is fine. Maybe it is a problem with my Desktop, which is LONG OVERDUE for a Reinstall. Out of curiosity, I would be interested if the issue happens to ANYONE else though. I have NEVER had this issue before.