I'm using PowerShell's Get-Content to read the contents of a file and store it in a variable, like this:
$VAR1 = Get-Content c:\file,info
The content looks like this:
"server":"https://somewebsite.com","newConfiguration":false,"proxy":"","site":"0088775487c2"
Now, I want to create a second variable that checks if the string "site":"0088775487c2" is in the file contents. If it's there, the variable should be set to "yes"; if not, it should be "no".
1 Answer
Have you tried using an if statement with a regex match? It sounds like you might not need a second variable at all. You can directly check for the presence of that string in your first variable. You could do something like this:
```powershell
$VAR1 = Get-Content c:\file,info
$exists = if ($VAR1 -match '"site":"0088775487c2"') {'yes'} else {'no'}
```
This way, you get 'yes' or 'no' right in the check! If you have any other specific requirements, let me know!
Thanks! That's exactly what I was looking for. I really appreciate the help!