PowerShell'de SharePoint Site Koleksiyonu, Site, Liste, Belge, Sütunun Var olup olmadığını kontrol edin


Site Koleksiyonu, Site, Liste, Belge (Dosya) ve sütun nesnelerinin belirli bir URL'sinin SharePoint'te mevcut olup olmadığını kontrol etmek için kullanışlı PowerShell komut dosyalarımı burada bulabilirsiniz. Gereken her yerde bu yardımcı işlevlerden yararlanabilirsiniz.

Site Koleksiyonunun Var olup olmadığını kontrol etmek için PowerShell:

İşte site koleksiyonunun mevcut olup olmadığını kontrol etmek için PowerShell ile özel işlevim ve işlev kullanımım. Site koleksiyonunun mevcut olup olmadığını kontrol etmek için SharePoint PowerShell:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom Function to Check if Site Collection Exists in Given URL
Function Check-SiteExists($SiteURL)
{
    return (Get-SPSite $SiteURL -ErrorAction SilentlyContinue) -ne $null     
}

#Variable for Site collection
$SiteURL= "https://demo.crescent.com/sites/operations" 

#Call the function to check site exists
if(Check-SiteExists($SiteURL))
{
    write-host "Yes, Given Site Collection Exists!" -f Green
    #Proceed with your script
}
else
{
    write-host "No, Site Collection doesn't Exists on given URL!" -f Red
}

Alternatif olarak şunları deneyebilirsiniz:


$SiteURL = "https://portal.crescent.com/"
 
Try{ 
    $Site=Get-SPSite $SiteURL -ErrorAction SilentlyContinue
}
catch{ 
    write-host Site Collection with URL:$SiteURL Does not Exists!
    return
}

Belirtilen URL'de SharePoint Alt Sitesinin mevcut olup olmadığını kontrol etmek için PowerShell Komut Dosyasını girin:


#Custom Function to Check subsite(Web) Exists or Not
Function Check-WebExists($WebURL)
{
    return (Get-SPWeb $WebURL -ErrorAction SilentlyContinue) -ne $null     
}

Listenin Mevcut Olup Olmadığını Kontrol Etmek için SharePoint PowerShell:


#Function to Check if List Exists 
Function Check-ListExists()
{
   Param( [Parameter(Mandatory=$true)] [string]$SiteURL, [Parameter(Mandatory=$true)] [string]$ListName ) 

   Return  (Get-SPWeb $SiteURL).lists.TryGetList($ListName) -ne $null
}

#Variable for Site collection
$varSiteURL= "https://intranet.crescent.com/sites/Sales"
$varListName = "Invoice"

#Call the function to check list exists
if(Check-ListExists -SiteURL $varSiteURL -ListName $varListName)
 {
      write-host "Yes, Given List do Exists!" 
      #Proceed with your script
 } 

PowerShell kullanarak Site Sütununun zaten mevcut olup olmadığını kontrol edin

PowerShell kullanarak site sütununun var olup olmadığını kontrol edelim:


#Function to Check if File Exists 
Function Check-SiteColumnExists()
{
   Param( [Parameter(Mandatory=$true)] [string]$SiteURL, [Parameter(Mandatory=$true)] [string]$ColumnName ) 

   Return  (Get-SPWeb $SiteURL).Fields.ContainsField($ColumnName) 
}

#Variable for Site collection
$varSiteURL= "https://intranet.crescent.com"
$varColumnName = "Department"

#Call the function to check list exists
if(Check-SiteColumnExists -SiteURL $varSiteURL -ColumnName $varColumnName)
{
    write-host "Yes, Given Site Column do Exists!" 
    #Proceed with your script
}

SharePoint PowerShell kontrol belgesi mevcut

Son olarak, belirli bir konumda dosyanın mevcut olup olmadığını kontrol edelim:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Function to Check if File Exists 
Function Check-FileExists()
{
   Param( [Parameter(Mandatory=$true)] [string]$SiteURL, [Parameter(Mandatory=$true)] [string]$FileURL ) 

   Return  (Get-SPWeb $SiteURL).GetFile($FileURL).Exists
}

#Variable for Site collection
$varSiteURL= "https://intranet.crescent.com"
$varFileURL = "https://intranet.crescent.com/Sales/Invoices/Inv-5060203.docx"

#Call the function to check list exists
if(Check-FileExists -SiteURL $varSiteURL -FileURL $varFileURL)
{
    write-host "Yes, Given File does Exist!" 
    #Proceed with your script
}

İlgili makaleler