Actually, you don't need to get the Id of the solution: solutions are identified by their file names (xxxx.wsp) OR their Id.
If a solution with the same file name is already added/deployed, you cannot add another one with the same file name...
[Update 1]
Manually, the Id can be extracted by renaming the .wsp to .cab, extracting the manifest.xml file and open it to find its SolutionId
attribute.
There should be a way to automate this through PowerShell.
[Update 2]
Here's the PowerShell code to automate it:
#Create a temp folder
$tempFolder = "C:\temp"
New-Item -ItemType Directory -Force -Path $tempFolder
# Extract the manifest.xml file from the wsp file
expand $fileNameSTR /f:manifest.xml $tempFolder
# Read the XML file and create namespace
$xml = [xml](Get-Content "$tempFolder\manifest.xml")
$xmlNsManager = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$xmlNsManager.AddNamespace("ns", "http://schemas.microsoft.com/sharepoint/")
# Get the SolutionId attribute of the Solution node
$identitySTR = $xml.SelectSingleNode('//ns:Solution', $xmlNsManager).SolutionId
$wspFIL
.