'osql' is not recognized as an internal or external command, operable program or batch file.
OSQL.exe does not exist on the machine you're running the script. Luckily, OSQL is a stand-alone utility. You can just copy it from another computer.
Or, if you prefer, run the script on a machine that has already installed the SQL Server Management tools.
XXX was unexpected at this time
The script must be missing the "^" symbol before a special symbol such as parenthesis. This would only happen if you changed the SQL statements section within the script.
Msg 170, Level 15, State 1, Server <ServerName>, Line 3
Line 3: Incorrect syntax near XXX.
The error above is an example of a SQL Server error due to incorrect syntax. This can also happen if you change the SQL statements in the script and you forgot to add the "^" symbol before a parenthesis.
Overcoming Basis challenges by reaching inside the database
Basis challenge #1: Reporting logon information
Basis challenge #2: Gathering SQL Server information
Basis challenge #3: Getting system profile parameters
Review: Conclusion and more resources