Wildcard in PowerShell Command

Should this work?

waithidden {pathname of file ((it as string) of value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of native registry)} -executionpolicy remotesigned -File "c:\temp\mdfi\*.ps1"

I have no idea the name of the .ps1 that will be in that folder as it chooses one from over 150 files based on the domain name of the server to place inside that folder so I really need it to run any old powershell (there will be only one in that folder).

Iā€™d suggest just trying the PowerShell command on a command line itself; I donā€™t know whether PowerShell accepts a wildcard for the script nameā€¦but if thereā€™s only one file there, you could always just use a second relevance substitution to retrieve the filename?

1 Like

I never thought about using the 2nd relevance idea :smiley:

So essentially getting the filename of the ps1 as a parameter then running it using that?

Yes, something like

waithidden {pathname of file ((it as string) of value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of native registry)} -executionpolicy remotesigned -File "{pathname of find file "*.ps1" of folder "c:\temp\mdfi"}"

The singular use of ā€˜fileā€™ and ā€˜folderā€™ there is intended, to throw a ā€˜singular expressionā€™ error and abort the script if there do happen to be more than one .ps1 files in that folder.

I went with this as I didnā€™t see you replied :smiley:

parameter "ps1"="names of files whose (name of it as lowercase ends with ".ps1") of folder "C:\tmp""

waithidden {pathname of file ((it as string) of value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of native registry)} -executionpolicy remotesigned -File "c:\temp\mdfi\"{parameter "ps1"}""

Havenā€™t tested it yet though :slight_smile:

I think youā€™ll need to delete the extra quotes outside the {parameter} substitution but otherwise yeah that should worktoo

1 Like

Shoot! Well spotted :smiley:

This should be it now (again not tested as the guy I need is off shift until tomorrow)

parameter "ps1"="{names of files whose (name of it as lowercase ends with ".ps1") of folder "C:\tmp")}"

waithidden {pathname of file ((it as string) of value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of native registry)} -executionpolicy remotesigned -File "c:\temp\mdfi\{parameter "ps1"}"