Jump to content

Recommended Posts

Posted (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 by DaveC-LHS
Posted
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
Posted

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"
}

  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...