DaveC-LHS Posted October 24, 2024 Posted October 24, 2024 (edited) Hi I am trying to write a PS script to create folders in a SharePoint document library using the content of an Import-CSV as a variable. The orginal script, PNP.Powershell Script to Create folders and set permissions via sharepoint/Teams, was failing so I've tried to rollback into the component parts of the script to find the issue. The following section of the script returns the correct values from the CSV. $libraryName = "" $folders=Import-csv "" # List of folders to create foreach ($folder in $folders) { $folder } However, changing the foreach statement to the following returns the $folder value as '@{folder=value}' as in (@{folder=value} \@{folder=value} does not exist. $libraryName = "" $folders=Import-csv "" foreach ($folder in $folders) { "$folder $libraryName\$folder does not exist" } Any help would be greatly appreciated. Edited October 24, 2024 by DaveC-LHS
jthompson Posted October 24, 2024 Posted October 24, 2024 You might need to reference the column heading from the CSV. For instance, if the relevant column heading was "FolderName", in your foreach you'd use $folder.FolderName instead of just $folder
jthompson Posted October 24, 2024 Posted October 24, 2024 Actually, instead of $folder.FolderName you'd need to use: $($folder.FolderName) So your code would be: $libraryName = "" $folders=Import-csv "" foreach ($folder in $folders) { "$($folder.FolderName) $libraryName\$($folder.FolderName) does not exist" } 1
DaveC-LHS Posted October 24, 2024 Author Posted October 24, 2024 Thanks @jthompson. I knew it would be something simple, but I had gone blind to it.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now