0

I've got a .txt file that I'm trying to get-content from, and I'm struggling to turn the gc into a variable... I'm running:

$variablesfile = gc .\Variables.txt

I've also put the entire filepath here instead of just .\Variables.txt, and I know I'm in the right directory because ISE is auto-filling the filepath and filename for me... But when I type $variablesfile it doesn't return any results... If I just go to PowerShell and type:

gc .\Variables.txt

it displays the information I want without issue, but I can't seem to declare it as a variable... Also, when I just type $VariablesFile to get the results, it doesn't see it as an existing variable.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Christopher Cass
  • 817
  • 4
  • 19
  • 31
  • Could you post the content of Variables.txt or sample data? – Persistent13 Mar 26 '18 at 21:57
  • The entire contents: 1am;test4 – Christopher Cass Mar 26 '18 at 21:58
  • Basically, I'm using a different ps1 file to have someone enter variables, which I'm putting into a .txt file, then invoke-command with a new ps1 file to remote servers, where I'm trying to pull those variables back out of the .txt file. – Christopher Cass Mar 26 '18 at 21:59
  • I'm not able to reproduce the issue, I populate the $variablesfile variable without issue. If you're trying to save the data for programatic use, why not save it as a json or clixml file instead? Export-Clixml and ConvertTo-Json would both assist you with that. – Persistent13 Mar 26 '18 at 22:01
  • Have you tried using the full path to Variables.txt instead of a relative path? – TheMadTechnician Mar 26 '18 at 22:20
  • Thanks guys. Nothing seemed to work for the variable in this script. I ended up just creating the script from scratch. The first thing I did was establish the variable, make sure it worked, then pasted everything else from the old script and it worked. As far as Export-Clixml and ConvertTo-Json... Basically I have no clue what I'm doing, so I'm just working with what I know. – Christopher Cass Mar 27 '18 at 16:16
  • Yeah, something is definitely funky with this script. I've got it finalized now, but every time I needed add a new variable to it, I had to completely recreate the script and start by establishing the new variables... Really weird... Unfortunately, I can't just throw the entire script in here for help, but something is obviously weird with this one. – Christopher Cass Mar 27 '18 at 21:13

0 Answers0