0
votes

I'm trying to figure out if there is syntax I can use to get content out of a file and only pull back a sub string of it all in one line? Something like the following, except it doesn't work, so I'm looking for the missing piece.

$ConfigureEmail = Get-Content -Path "\\myFilePath\Location\MyFile.sql" -Raw | $_.SubString($_.IndexOf("*/"))

I'm trying to pull the main script out of the file, starting after the comment block.

Edit: I realized I could add Foreach-Object after the pipe but since I will only ever have one item is there something better to use?

1

1 Answers

1
votes
$Content = Get-Content -Path "\\myFilePath\Location\MyFile.sql" -Raw
$ConfigureEmail = $Content.SubString($Content.IndexOf("*/"))

->

$ConfigureEmail = ($Content = Get-Content -Path "\\myFilePath\Location\MyFile.sql" -Raw).SubString($Content.IndexOf("*/"))

or

[regex]::Match((Get-Content .\test.txt -Raw), '\*/.*', 'singleline').Value