d365collaborative / d365fo.tools

Tools used for Dynamics 365 Finance and Operations
MIT License
250 stars 102 forks source link

Calling Rename-D365ComputerName with invalid name results in error, but executes rest of script #656

Open FH-Inway opened 2 years ago

FH-Inway commented 2 years ago

When running [Rename-D365ComputerName]() with an invalid -NewName parameter (e.g. d365fo.tools), the rename fails with an error message saying "Rename-Computer : Skip computer 'MININT-57EHFHJ' with new name 'd365fo.tools' because the new name is not valid.". Despite this, the the rest of the cmdlet is executed.

Another run of the cmdlet with a valid name renames the computer correctly, but now execution of the rest of the cmdlet causes issues: "Something went wrong while working against the database. | Exception calling "ExecuteNonQuery" with "0" argument(s): "The server 'MININT-57EHFHJ' does not exist. Use sp_helpserver to show available servers. The server 'd365fo-tools' already exists.""

Not sure yet if this breaks the environment.

Gist with full PowerShell session

FH-Inway commented 2 years ago

Have to do some more testing, but no matter the outcome, I think the cmdlet should be modified to not execute the rest if Rename-Computer fails.

valerymoskalenko commented 2 years ago

Try to use -EnableException parameter to stop the execution of the script