Home > Software design >  Powershell wildcard for path with different language in Windows\System32\ Folder
Powershell wildcard for path with different language in Windows\System32\ Folder

Time:08-24

The original location to run the cscript is here for en-US Windows devices:

cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\Prndrvr.vbs"

What I need is to allow any other languages where xx-xx could be en-US, en-GB, de-DE, nl-NL, etc

"C:\Windows\System32\Printing_Admin_Scripts\xx-xx\Prndrvr.vbs"

I've tried using * in different ways but I guess I'm not getting the right combo.

The script is executing the .vbs file to install the printer.

Thanks!

CodePudding user response:

Start by seeing if you can locate the version that corresponds to the current UI locale:

$UIlocale = Get-UICulture
$localizedPath = 'C:\Windows\System32\Printing_Admin_Scripts\{0}\Prndrvr.vbs' -f $UIlocale.Name

if(Test-Path $localizedPath){
  & cscript $localizedPath
}
elseif(Test-Path 'C:\Windows\System32\Printing_Admin_Scripts\en-US\Prndrvr.vbs') {
  # fallback to en-US version
  & cscript 'C:\Windows\System32\Printing_Admin_Scripts\en-US\Prndrvr.vbs'
}
else {
  # attempt to find _any_ version of the script, select the first one found
  $printScript = Get-ChildItem -Path 'C:\Windows\System32\Printing_Admin_Scripts\??-??\*' -Filter Prndrvr.vbs |Select -First 1
  if($printScript){
    & cscript $printScript.FullName
  }
  else {
    Write-Error "Unable to locate print management script!"
  }
}

CodePudding user response:

I did something different.

I created a variable before the command runs declared as $Printerscript

Then I used Resolve-Path so it looks something like:

$PrndrvrVBS = Resolve-Path "C:\Windows\System32\Printing_Admin_Scripts\*\Prndrvr.vbs"

So the final outcome is

#VBScript Prndrvr Path
$PrndrvrVBS = Resolve-Path "C:\Windows\System32\Printing_Admin_Scripts\*\Prndrvr.vbs" 

cscript "$PrndrvrVBS" 
  • Related