Hi,
I’m trying to upgrade powershell version on windows server 2008R2 through powershell commands.
if I run those commands on powershell directly it is working fine but if use same commands in ansible playbook it is throwing Fatal Error.
My guess is that is because you are also replacing Windows Management Framework, which includes WinRM, which is the mechanism used to communicate with the windows machine. If the WinRM service gets restarted during the upgrade I can imagine this will fail.
You might be able to get around this by setting up a scheduled task to run the installation - but this is not something I have tried myself.
The example you gave to install .net 4.5 is an MSU file that is installed with Windows update. There is no easy way to install update files but I’ve been able to install .net 4.5 using the offline installer that is packages as an exe. The link for it is here https://www.microsoft.com/en-au/download/details.aspx?id=42642.
As jhawkesworth was saying there isn’t an easy way to upgrade powershell as it is like pulling the rug out when you are standing on it. You might have luck with scheduled tasks or running with async and no polling but I’ve yet to find an easy way to do this.