Solving PowerShell Issues Post-Windows Update

Hue Truong

I’m sharing this experience so that it will help someone out there who encounter the same issue with their PowerShell scripts.

Problem

One of my PowerShell scripts suddenly stopped running on its schedule, and I had to run it manually. One of the errors I encountered is shown below.

Get-Date : The "Get-Date" command was found in the module 'Microsoft.PowerShell.Utility', but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.

Troubleshooting

It’s worth noting that while the function originated from Windows PowerShell, it doesn’t work in Microsoft PowerShell 7. In response, I proceeded to execute the suggested code, ‘Import-Module Microsoft.Powershell.Utility.’

Import-Module Microsoft.Powershell.Utility

Unfortunately, this action resulted in an error message.

Import-Module: The module to process 'Microsoft.PowerShell.Commands.Utility.dll', listed in field 'NestedModules' of module manifest 'C:\program files\powershell\7\Modules\microsoft.powershell.utility\microsoft.powershell.utility.psd1' was not processed because no valid module was found in any module directory.

After conducting further investigation, I discovered that the Windows Server had applied an update earlier that morning.

2023-12 Cumulative Update for Windows Server 2019 (1809) for x64-based Systems (KB5033371)

I downloaded the CSV file containing updates and searched for “Microsoft.PowerShell.Commands.Utility.dll”.

# type 5033371.csv | findstr "Microsoft.PowerShell.Commands.Utility.dll"
"Microsoft.PowerShell.Commands.Utility.dll","10.0.17763.4974","29-Sep-2023","17:23","6,768,640"
"Microsoft.PowerShell.Commands.Utility.dll","10.0.17763.4974","29-Sep-2023","16:58","6,768,640"
"Microsoft.PowerShell.Commands.Utility.dll","10.0.17763.4974","29-Sep-2023","16:49","6,768,640"

It seems that my Microsoft PowerShell 7 scripts stopped working due to a corruption in “Microsoft.PowerShell.Commands.Utility.dll” after the Windows Server update.

Solution

I was struggling to figure out how to obtain a functioning version of “Microsoft.PowerShell.Commands.Utility.dll” and transfer it to the server. However, I decided to take a shortcut instead. I took necessary precautions by backing up the server and taking a snapshot to revert to if needed.

As I had Microsoft PowerShell Core v7.3.10 installed, I downloaded the latest version which was Microsoft PowerShell Core v7.4.0. After installation, I rebooted the server.

Upon logging back in, I tested the Get-Date command again and it worked without issue.

I am sharing with you the list of Microsoft.PowerShell.Commands.Utility.dll files that I had on the Windows Server before the upgrade.

Directory of C:\Program Files\AzureConnectedMachineAgent\GCArcService\GC

12/09/2023  02:47 AM           811,952 Microsoft.PowerShell.Commands.Utility.dll
               1 File(s)        811,952 bytes

Directory of C:\Program Files\PowerShell\7

11/15/2023  01:31 AM         1,632,296 Microsoft.PowerShell.Commands.Utility.dll
               1 File(s)      1,632,296 bytes

Directory of C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Utility\1.0.0.0__31bf3856ad364e35

09/14/2018  11:13 PM           667,648 Microsoft.PowerShell.Commands.Utility.dll
               1 File(s)        667,648 bytes

Directory of C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Utility\v4.0_3.0.0.0__31bf3856ad364e35

11/07/2023  08:16 AM         6,768,640 Microsoft.PowerShell.Commands.Utility.dll
               1 File(s)      6,768,640 bytes

After the upgrade, the Windows Server contains the following Microsoft.PowerShell.Commands.Utility.dll files.

Directory of C:\Program Files\AzureConnectedMachineAgent\GCArcService\GC

12/09/2023  02:47 AM           811,952 Microsoft.PowerShell.Commands.Utility.dll
               1 File(s)        811,952 bytes

Directory of C:\Program Files\PowerShell\7

11/11/2023  01:59 AM         1,673,144 Microsoft.PowerShell.Commands.Utility.dll
               1 File(s)      1,673,144 bytes

Directory of C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Utility\1.0.0.0__31bf3856ad364e35

09/14/2018  11:13 PM           667,648 Microsoft.PowerShell.Commands.Utility.dll
               1 File(s)        667,648 bytes

Directory of C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Utility\v4.0_3.0.0.0__31bf3856ad364e35

11/07/2023  08:16 AM         6,768,640 Microsoft.PowerShell.Commands.Utility.dll
               1 File(s)      6,768,640 bytes

Conclusion

It appears that the update caused an issue by replacing the “Microsoft.PowerShell.Commands.Utility.dll” file with an incompatible version. However, the problem was resolved by installing the latest version of Microsoft PowerShell Core, which replaced the incompatible version of the file. If this solution helped you or if you have any other ideas about what might have caused the issue, please leave a comment.

join the conversation

Leave the first comment

Avatar for Hue Truong

Hue Truong

IT Professional, Systems Engineer, and Cloud Administrator. Passionate about exploring the latest technologies and solving complex problems.

Related Posts

More articles like this