I have a text file (on local filesystem) that is a map of ID values with file names:
1111, testfile1.xml 2222, testfile2.xml 3333, testfile3.xml
Each line is a map entry, so "1111" is the corresponding ID value for testfile1.xml.
I'm trying to post each testfile to an endpoint, but need to grab the associated ID value that corresponds to the file since it is needed in the URI of the endpoint that we are POST-ing to.
Code snippet from my script that recurses a directory that contains all the testfilex.xml's and does the POST:
$testFiles = Get-ChildItem $testFileDir
$mapFileLocation = "C:/local/Desktop/map.txt"
foreach ($file in $testFiles) {
$content = Get-Content $file.PSPath
#$id = GRAB ID HERE /*TODO*/
$URI = "http://www.myendpoint:1000/" + $id
$request = Invoke-WebRequest -Uri $URI -Method PUT -Body $content -ContentType "application/xml"
Is there any way I can build $id like this via PowerShell? Possibly by regex-ing? Can text files even be parsed like this?
Import-Csv?