Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

Joining variables together

$
0
0

I have only just stated learning PS and I want to create a folder path using variables.

This is the script

$root="C:\pstest\"

$folder=import-csv "C:\pstest\folder.csv"

Foreach ($directory in $folder){

write-host $root$directory

}

$folder outputs this

C:\Windows\system32> $folder

 

Directory                                                                                                                                                                                                                        

---------                                                                                                                                                                                                                       

AAAA                                                                                                                                                                                                                             

BBBB                                                                                                                                                                                                                             

CCCC                                                                                                                                                                                                                             

DDDD                                                                                                                                                                                                                             

CCCC                                                                                                                                                                                                                             

EEEE                                                                                                                                                                                                                             

GGGG          

 

This is the csv

PS C:\Windows\system32> type C:\PSTest\folder.csv

Directory

AAAA

BBBB

CCCC

DDDD

CCCC

EEEE

GGGG

I want an output like

C:\pstest\AAAA

C:\pstest\BBBB  etc

But what I get is

C:\pstest\@{Directory=AAAA}

C:\pstest\@{Directory=BBBB}

 

The aim is I have to verify the existence of a folder and if it doesn't exist create it. I worked out that bit but I want script is as I have to check 2500 folders the $root bit stays the same for all the folders so I was trying to shorten the code by using a variable and at the same time learn how to joining variables like this together


Viewing all articles
Browse latest Browse all 8411

Latest Images

Trending Articles



Latest Images