Link to home
Start Free TrialLog in
Avatar of CES
CES

asked on

Powershell - Set-Location using a variable

I am trying to write a script that pulls the name of a sub-directory from a file and then moves into that sub folder.  The idea being that the file contents can change and thus the sub directory can change as well:

Here is a toned down example of what I am doing but it will give a good enough idea that i think and responses will get me my answer

Set-Location C:\temp
$folder = get-content c:\temp\folder.txt (folder.txt will have only the name of a sub folder in this directory)

What I am trying to then accomplish is something along the lines of:
Set-Location c:\temp\$folder

I have not been able to figure out exactly what I need to do this.  I've tried Tee-Object, Invoke-Command, invoke Item, get-childItem, etc... all to no avail.

Any help would be much appreciated!
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CES
CES

ASKER

I found that my get-content file had and extra space so power shell was incorporating that space

Thanks for the second set of eyes. That at least confirmed that it had my script write, indicating that it had to be a flaw with the data.