Read specific value from file

Hey guys, I’m a linux admin by trade and haven’t dealt with powershell too much, but I have a task that needs to be run on a Windows server and having a little bit of an issue.

I have a list of powershell modules that I am packaging for our local chocolatey server and am building a script to do all the work, but running into a slight issue with reading the psd1 files for these modules. I am using the Import-PowerShellDataFile cmdlet to pull the ModuleVersion from these psd1 files however it fails on a few (and I have no idea why as they look to be formatted correctly) so I decided to just find the relevant line in the file, ModuleVersion = “1.0.0.0” and just pull the version number out, however I am having some trouble doing this easily. In linux I would do something along the lines of grep ModuleVersion | awk -F ‘=’ { print $1}, but can’t seem to find something as simple in powershell….

Using powershell 5 if that helps.

submitted by /u/codingQueries
[link] [comments]

Leave a Reply