0

The Problem:

I have inherited a PS script file that deletes a directory. In case there are any locks on it, it removes them using this line:

Get-SmbOpenFile | Where-Object -Property Path -Like "$($Directory)*" | Close-SmbOpenFile -Force

This works in PowerShell 5. I have recently installed Powershell 7 on this machine to use some of it's features.

Now when I run this script in PS7, this error appears:

The 'Get-SmbOpenFile' command was found in the module 'SmbShare', but the module could not be loaded. For more information, run 'Import-Module SmbShare'.

Now I ran the 'Import-Module SmbShare' command in PS7 it it said:

Import-LocalizedData: Cannot find the PowerShell data file 'SmbLocalization.psd1' in directory 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\SmbShare\de-DE', or in any parent culture directories.

Which is correct. My system language is de-DE and there is no such file or folder. It only contains /en-US/.

What I have tried so far:

Whenever I run Import-Module SmbShare in a PS5 console, where it works, it then subsequently works for any PS7 consoles that were open at that time. If I open and close the PS7 console, it stops working in the new consoles and returns to it's old error messages.

I tried Install-Module or Update-Module but it does not seem to be that kind of module, because none of those commands work. The module seems to come with Powershell 1 and is not available in the PSGallery. I read somewhere in a blog post that I have to install the language pack. The language that is missing is the language of the server. It is fully installed. However, when I try to Install-Language, it tells me that the commandlet is not recognized and when I try Import-Module LanguagePackManagement it tells me that is not a recognized module, although I am running "Windows Server 2022 Standard" (21H2) where it should be according to the documentation.

Another "fix" suggested online was to just set my script language to en-US. Well, it's about 16 scripts that so far relied on the culture being de-DE, with en-US not even explicitely installed (I know it is anyway), and it seems to me that this fix would probably break more and in weirder ways than it is supposed to repair.

I even tried to ask ChatGPT and I got a reply that demonstrates why we do not want AI generated answers here. It suggested as a last resort I set the UseCulture Parameter to en-US for this module: Import-Module SmbShare -UseCulture en-US. A solution that sounds great and was described very convincingly, one little problem with it: that parameter does not actually exist.

Help me Obi-Wan...

I am not a Powershell expert. Maybe this is some dumb mistake on my part. But I don't see it. Wherever I turn, I get error messages and none is in any way helpful or constructive.

Does anybody know how to fix this error?

nvoigt
  • 75,013
  • 26
  • 93
  • 142

1 Answers1

0

I have now "solved" (maybe I should say duct taped) the problem by going into the powershell installation directory and simply cloning the "en-US" folder into a new "de-DE" folder with no changes. Now the module can be imported without problems.

I do not consider this a proper solution. It's just a band-aid I wanted to share if anybody else encounters this and needs a quick and dirty fix.

So I am still happy to see an alternative and hopefully better answer than this one.

nvoigt
  • 75,013
  • 26
  • 93
  • 142