Voraussetzungen

Wie auch in meinem Artikel über das Provisionieren von Websitespalten braucht man, um mit der PowerShell und Office 365 arbeiten zu können, die SharePoint-Client Umgebung.

Darüber hinaus muss man folgende Einstellungen machen:

  • Man muss nach dem Auspacken des angebotenen zip-Files in den File-Attributen das Häkchen entfernen, dass die Datei gefährlich ist, weil aus dem Internet
  • Man muss die Execution Policy der PowerShell auf unrestricted setzen.
  • Man muss in der machine.config des .NET-Frameworks folgende Erweiterung eintragen:

<configuration>
<runtime>
<loadFromRemoteSources enabled=“true“/><
</runtime>
</configuration>

Das Script

[System.Reflection.Assembly]::LoadFrom(„C:TempMicrosoft.SharePoint.Client.dll“)
# define target SPO site collection and credentials to connect with
$siteUrl = “https://<target>.sharepoint.com/”
$username = „<userName>“
$password = Read-Host -Prompt „Enter password“ -AsSecureString

# connect and authenticate to SPO
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$ctx.Credentials = $credentials

# retrieve all site columns (fields)
$web = $ctx.Web
$ctx.Load($web)
$fields = $web.Fields
$ctx.Load($web)
$ctx.Load($fields)
$ctx.ExecuteQuery()

$fields = $fields  | Where {$_.Group -eq „QMS“}

foreach($field in $fields)
{
write-host $field.Id, $field.InternalName

$lists = $web.Lists
$ctx.Load($lists)
$ctx.ExecuteQuery()

foreach($list in $lists)
{
$listTitle = $list.Title
$listflds = $list.Fields
$ctx.Load($listflds)
$ctx.ExecuteQuery()

foreach($listFld in $listflds)
{
if ($listFld.InternalName -eq $field.InternalName)
{
write-host „!!! Found occurence in List >> $listTitle“ -ForegroundColor Red
}
}

#Get All Content Types
$contentTypes = $web.ContentTypes
$ctx.Load($web)
$ctx.Load($contentTypes)
$ctx.ExecuteQuery()

foreach($ContentType in $contentTypes)
{
$fieldLinks = $ContentType.FieldLinks
$ctx.Load($fieldLinks)
$ctx.ExecuteQuery()

$FieldInUse = $fieldLinks | Where {$_.Name -eq $field.InternalName}
if($FieldInUse -ne $null)
{
Write-Host „Found the Column in Content Type:“ $ContentType.Name -ForegroundColor DarkGreen
##To Remove the field from content type, uncomment below two lines
#$ContentType.FieldLinks.Delete($ColumnInternalName)
#$ContentType.Update()
}
}
}

Ist doch cool, oder?

LG,
Sabine