PowerShell, SharePoint Belge Kitaplığı'nda Klasör Oluşturmak için
Gereksinim: SharePoint Server Belge Kitaplığı'nda yeni bir klasör oluşturun.
PowerShell kullanarak SharePoint Belge Kitaplığı'na nasıl klasör eklenir?
PowerShell'i kullanarak SharePoint'te hızlı bir şekilde klasörler oluşturabilirsiniz. Bu blog gönderisinde, SharePoint belge kitaplığında yeni bir klasör oluşturmak için PowerShell'in nasıl kullanılacağı öğrenilecek.
SharePoint Server'daki belge kitaplığında bir klasör oluşturmak için bu PowerShell betiğini kullanın:
$folder = $list.Folders.Add("", [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, "New")
$folder.Update()
Yukarıdaki komut dosyası pek fazla hata toleransı sağlamıyor, değil mi?
- Peki ya aradığımız belirli bir kütüphane mevcut değilse?
- Eklemeye çalıştığımız klasör zaten kütüphanede mevcutsa ne olur?
Hata! O halde gelin kodu PowerShell'de çok az hata toleransıyla yeniden yazalım!
PowerShell Kullanılarak SharePoint Listesinde Klasörler ve Alt Klasörler Nasıl Oluşturulur?
SharePoint Listesi veya Kitaplığı içinde Klasörler ve Alt Klasörler oluşturmaya yönelik PowerShell kod pasajını burada bulabilirsiniz:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get the Web
$web=Get-SPWeb "https://sharepoint.company.com"
#Get the List/Library
$list=$web.Lists.TryGetList("SalesList")
If($list) #Check If List exists!
{
#Check Folder Doesn't exists in the Library!
$folder = $list.ParentWeb.GetFolder($list.RootFolder.Url + "/" +"Sales List");
#sharepoint powershell check if folder exists
If($folder.Exists -eq $false)
{
#Create a Folder
$folder = $list.AddItem([string]::Empty, [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, "Sales Sub-Item")
$folder.Update();
}
#Create a Sub-Folder "APAC Sales Documents" inside "Sales Documents"
$Subfolder = $list.ParentWeb.GetFolder($folder.URL + "/" + "APAC Sales Documents");
#Check if sub-folder doesn't exist already
If ($Subfolder.Exists -eq $false)
{
#Create a Sub-Folder Inside "Sales Documents"
$Subfolder = $list.AddItem($folder.URL, [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, "APAC Sales Documents")
$Subfolder.Update();
}
}
SharePoint Kitaplığı'nda iç içe geçmiş bir klasör yapısı sağlamaya ne dersiniz? Örneğin. Kitaplık/KlasörA/KlasörAA/KlasörAAA
#Get the Web
$web=Get-SPWeb "https://sharepoint.company.com"
#Get the List/Library
$list=$web.Lists.TryGetList("Documents")
#Function to Ensure FolderPath
Function Ensure-FolderPath($FolderPath)
{
$SubFolders = $FolderPath -split "/"
$RootFolder = $SubFolders[0]
$SubfolderPath = $RootFolder
For($i =1; $i -le $SubFolders.count-1; $i++)
{
$SubfolderPath = $SubfolderPath+"/"+$SubFolders[$i]
$Folder = $Web.GetFolder($SubfolderPath)
#Create Folder if it doesn't exists
If($Folder.Exists -eq $false)
{
$TargetFolder = $Web.Folders.Add($SubfolderPath)
Write-host "Folder Created:"$SubfolderPath
}
}
}
#Call the function to Ensure Folder Path
Ensure-FolderPath "Documents/Technical Design/Assorted/2020"
