SharePoint Online: PowerShell Kullanarak Seçim Alanı Değerini Belirleyin
Gereksinim: PowerShell'i kullanarak SharePoint Online'da Seçim Alanı Değerini Alın/Ayarlayın.
PowerShell, SharePoint Online'daki Bir Liste Öğesinden Seçim Alanı Değerini Almak için:
Bu blog gönderisinde PowerShell kullanarak SharePoint Online'da bir seçim alanının değerinin nasıl alınacağı veya ayarlanacağı araştırılacaktır. SharePoint Online'a bağlanmak için PowerShell'in nasıl kullanılacağını ele alacağız ve ardından liste öğelerinin seçim sütununun değerini almak veya güncellemek için kullanılabilecek bazı kod örneklerine bakacağız.
SharePoint Online'da seçim sütunu değerlerini okumak için PowerShell betiği aşağıda verilmiştir:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Parameters
$SiteURL = "https://Crescent.sharepoint.com"
$ListName ="Projects"
$FieldName = "Project_x0020_Status" #Internal Name of the Field
$ItemID = 10
#Get credentials to connect
$Cred = Get-Credential
Try {
#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName, $Cred.Password)
#Get the List Item
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$ListItem = $List.GetItemById($ItemID)
$Ctx.Load($ListItem)
$Ctx.ExecuteQuery()
#Get the value of Choice Field
Write-Host $ListItem[$FieldName]
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
CSOM PowerShell'i kullanarak Çoktan Seçmeli Sütun Değeri Alma
Birden fazla seçeneği kabul etmesine izin verilen bir Seçim sütunundan değerleri almak için bu PowerShell betiğini kullanın:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Parameters
$SiteURL = "https://crescent.sharepoint.com"
$ListName ="Projects"
$FieldName = "Category"
$ItemID = 10
#Get credentials to connect
$Cred = Get-Credential
Try {
#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName, $Cred.Password)
#Get the List Item to update
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$ListItem = $List.GetItemById($ItemID)
$Ctx.Load($ListItem)
$Ctx.ExecuteQuery()
#Get Multiple Choices Field Value from the List Item
$FieldValues = $ListItem[$FieldName]
#Print Each Value Selected
ForEach($Value in $FieldValues)
{
Write-host $Value
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
PowerShell kullanarak SharePoint Online'da Seçim Alanı Değerini Ayarlama
Bir liste öğesinin seçim alanı değerini güncellemek için PowerShell buradadır:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Parameters
$SiteURL = "https://crescent.sharepoint.com"
$ListName ="Projects"
$FieldName = "Project_x0020_Status"
$ItemID = 10
#Get credentials to connect
$Cred = Get-Credential
Try {
#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName, $Cred.Password)
#Get the List Item to update
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$ListItem = $List.GetItemById($ItemID)
$Ctx.Load($ListItem)
$Ctx.ExecuteQuery()
#Update the value of Choice Field in the List Item
$ListItem[$FieldName] = "Active"
$ListItem.Update()
$Ctx.ExecuteQuery()
Write-host -f Green "Choice Field Value has been updated for the list Item!"
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
Çoktan Seçmeli Alan Değerini Güncellemek için CSOM PowerShell Komut Dosyası
Benzer şekilde, birden fazla seçeneğe izin veren bir Seçim alanının değerini ayarlamak için bu PowerShell'i kullanın:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Parameters
$SiteURL = "https://crescent.sharepoint.com"
$ListName ="Projects"
$FieldName = "Category"
$ItemID = 10
#Get credentials to connect
$Cred = Get-Credential
Try {
#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName, $Cred.Password)
#Get the List Item to update
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$ListItem = $List.GetItemById($ItemID)
$Ctx.Load($ListItem)
$Ctx.ExecuteQuery()
#Update the value of Multiple Choices Field in the List Item
$ListItem[$FieldName] = @("Development", "IT Applications", "Real Estate")
$ListItem.Update()
$Ctx.ExecuteQuery()
Write-host -f Green "Choice Field Value has been updated for the list Item!"
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
PnP PowerShell Seçim Alanı Değerini Güncelleyecek:
Seçim alanı değerlerini PnP PowerShell kullanarak güncellemek için şunu kullanın:
#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/PMO"
$ListName = "Projects"
$ItemID = 1
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Update choice column value using PowerShell
Set-PnPListItem -List $ListName -Identity $ItemID -Values @{"Status"= "Completed"}
Bu komut dosyası "Durum" alanı değerini "Tamamlandı" olarak ayarlar. Benzer şekilde, Çoklu seçimler için bunları “;#” (noktalı virgül ve # sembolü) ile ayırın. Örneğin.,
Set-PnPListItem -List $ListName -Identity $ItemID -Values @{"Industries"= "Aerospace;#Automation;#Energy"}
Kapanıyor
Özetle, SharePoint Online'daki bir seçim alanının değerini almak veya güncellemek için PowerShell'i kullanmak, SharePoint Online'da depolanan verilere erişmenin ve bunları yönetmenin etkili bir yoludur. Yukarıda sağlanan komut dosyalarını kullanarak, bir seçim alanının değerini hızlı ve kolay bir şekilde alabilir, değiştirebilir ve yeni değeri SharePoint Online liste öğelerine kaydedebilirsiniz.
Seçim alanındaki mevcut seçenekleri güncellemek istiyorsanız şunu kullanın: SharePoint Online'da Seçim Alanındaki Seçimleri Güncellemek için PowerShell
