In my system Powershell 7.x and powershell 5.x was there. However, as per Microsoft Powershell docs, version 5.x is integrated with core components. hence, I uninstalled the powrshell 7.x. The build got succeeded