0

so right now I am working in Powershell and am working with my first Hash Table. So with my code I have a variable that gets the Metadata of the file and I want that variable to pass through a hash table to get to shorten the Metadata. For example the file I'm working with is version v2.0.50727 which I want to turn into "lib\net20" I know the set up I have now doesn't work, I think I need to do a substring to get what I want but I have no idea how to set that up.

$retCode = 0
        write-verbose "Getting version of $file..."
        $version = (Get-Item $File).VersionInfo.FileVersion
        $id = $file.Substring(0, $File.LastIndexof('.'))
        $filepath = Get-ChildItem "$File"
        $netVer = ildasm /text $File| findstr Metadata
        $OriginalFilename = (Get-Item $File).VersionInfo.OriginalFilename
        #Some type of substring to turn v2.0.50727 into 2.0
        $netVerConv = @{2.0 = "lib\net20";}

I thinking that I need some type of foreach loop but I honestly have no idea here. Ultimately the Hash Table will look something like this

        $netVerConv = @{
        2.0 = "lib\net20";
        3.0 = "lib\net30";
        3.5 = "lib\net35";
        4.0 = "lib\net40";
        }    

1 Answer 1

2

Try this:

$file = 'C:\windows\explorer.exe'
$version = (Get-Item $file).VersionInfo

$ShortVer = '{0}.{1}'-f $version.FileMajorPart,$version.FileMinorPart
$ShortVer
6.1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.