Hi,
I want to write a powershell script to execute all the files in a directory, by alphabetical order. Problem is, I also want to execute each file in the directory. How can I do this last bit?
Thanks
Hi,
I want to write a powershell script to execute all the files in a directory, by alphabetical order. Problem is, I also want to execute each file in the directory. How can I do this last bit?
Thanks
gci | ?{$_ -is [io.fileinfo]} | ii
You can use the path parameter of Get-ChildItem to chose the directory.
Update: Limited selection to only files. Was all items in a directory.
Use get-childitem to find all the items in the directory you want. You can then convert this list into a list of strings where each string is the name of a file.
Then use the "&" operator to execute each file.
I.E.
gci | select name | foreach-object { & $_.tostring() }
something like that.
See: http://technet.microsoft.com/en-us/library/ee176949.aspx
I would use:
Get-ChildItem -filter *.exe |
Invoke-Item
You asked for only the programs in a directory. The IO.FileInfo answer will open word documents as well as run programs. So will the answer with &. You don't have to sort alphabetically, because that's how the files come back anyways, but you could put a Sort-Object in the middle if you'd like.
Hope this helps,