Home

Add Folders with metadata using PowerShell script

%3CLINGO-SUB%20id%3D%22lingo-sub-297073%22%20slang%3D%22en-US%22%3EAdd%20Folders%20with%20metadata%20using%20PowerShell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-297073%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EAny%20code%20samples%20for%20creating%20SharePoint%20folders%20with%20metadata%20into%20a%20document%20library%3F%26nbsp%3BI'd%20like%20to%20import%20a%20list%20from%20CSV%20but%20I've%20only%20seen%20a%20sample%20where%20it%20adds%20the%20folder%20and%20changes%20permission.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%26nbsp%3B%3C%2FP%3E%3CP%3EFred%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-297073%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDocument%20Library%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-297715%22%20slang%3D%22en-US%22%3ERe%3A%20Add%20Folders%20with%20metadata%20using%20PowerShell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-297715%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Fred%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Ekeep%20the%20default%20SPFileSystemObjectType%3A%3AFolder%20.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThanks%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EThuyavan%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-297622%22%20slang%3D%22en-US%22%3ERe%3A%20Add%20Folders%20with%20metadata%20using%20PowerShell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-297622%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F240914%22%20target%3D%22_blank%22%3E%40Thuyavan%20Ganesan%3C%2FA%3E%3C%2FP%3E%3CP%3EDo%20I%20need%20to%20specify%26nbsp%3Bin%20the%20script%20if%20I'm%20using%20custom%20folder%20content%20type%20with%20the%20metadata%2C%20or%20will%20the%20default%20SPFileSystemObjectType%3A%3AFolder%20work%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%26nbsp%3B%3C%2FP%3E%3CP%3EFred%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-297119%22%20slang%3D%22en-US%22%3ERe%3A%20Add%20Folders%20with%20metadata%20using%20PowerShell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-297119%22%20slang%3D%22en-US%22%3EHello%20Fred%2C%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20you%20are%20talking%20about%20a%20folder%20with%20the%20metadata%20in%20SP%20library.And%20assume%20you%20have%203%20metadata%20for%20each%20folder.%3CBR%20%2F%3E%3CBR%20%2F%3E%24web%20%3D%20Get-SPWeb%20%3CA%20href%3D%22http%3A%2F%2Fwebapp.com%2Fsite%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwebapp.com%2Fsite%2F%3C%2FA%3E%3CBR%20%2F%3E%24list%20%3D%20%24web.GetList(%22%2Fsite%2FLibrary%20Name%22)%3CBR%20%2F%3E%3CBR%20%2F%3ECreate%20a%20folder%20with%20defined%20metadata%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%24spFolder%20%3D%20%24list.AddItem(%22%22%2C%5BMicrosoft.SharePoint.SPFileSystemObjectType%5D%3A%3AFolder%2C%22Folder%20Name%22)%3CBR%20%2F%3E%24spFolder%5B%22Col%201%22%5D%3D%22Cont%201%22%3CBR%20%2F%3E%24spFolder%5B%22Col%202%22%5D%3D%22Cont%202%22%3CBR%20%2F%3E%24spFolder%5B%22Col%203%22%5D%3D%22Cont%203%22%3CBR%20%2F%3E%24spFolder.Update()%3CBR%20%2F%3E%3CBR%20%2F%3EPlease%20let%20me%20know%20if%20that%20works%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%2C%3CBR%20%2F%3EThuyavan%3CBR%20%2F%3E----------------------------------------------------------------------------------%3CBR%20%2F%3E%3CBR%20%2F%3EYour%20%E2%80%9CLikes%E2%80%9D%20are%20energy%20boosters%20for%20us%20to%20keep%20blogging%20and%20the%20feedback%20is%20very%20valuable%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E
Highlighted
Frequent Contributor

Hi,

Any code samples for creating SharePoint folders with metadata into a document library? I'd like to import a list from CSV but I've only seen a sample where it adds the folder and changes permission. 

 

Thanks! 

Fred

 

3 Replies
Hello Fred,

If you are talking about a folder with the metadata in SP library.And assume you have 3 metadata for each folder.

$web = Get-SPWeb http://webapp.com/site/
$list = $web.GetList("/site/Library Name")

Create a folder with defined metadata:

$spFolder = $list.AddItem("",[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,"Folder Name")
$spFolder["Col 1"]="Cont 1"
$spFolder["Col 2"]="Cont 2"
$spFolder["Col 3"]="Cont 3"
$spFolder.Update()

Please let me know if that works

Thanks,
Thuyavan
----------------------------------------------------------------------------------

Your “Likes” are energy boosters for us to keep blogging and the feedback is very valuable

Hi, @Thuyavan Ganesan

Do I need to specify in the script if I'm using custom folder content type with the metadata, or will the default SPFileSystemObjectType::Folder work? 

 

Thanks, 

Fred

 

Hi Fred,

 

keep the default SPFileSystemObjectType::Folder .

 

Thanks,

Thuyavan

 

Related Conversations
General folder automatically created
AI_birder in Microsoft Teams on
4 Replies
Users can disable search
Jaroslav Karlik in OneDrive for Business on
12 Replies
Uploading .OAR file on One Drive
Uy1234 in OneDrive for Business on
2 Replies
Create folder structures in FILES
Rene Waldboth in Yammer on
3 Replies