Last active
August 29, 2015 14:22
-
-
Save sebastienlevert/782dcb48da21391fb19d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.DESCRIPTION | |
Sets a field visibility (Display Form, New Form, Edit Form, Hidden) | |
.PARAMETER Field | |
The Field to modifiy its visibility settings | |
.PARAMETER ShowInDisplayForm | |
If we want the field to be visible in the DisplayForm | |
.PARAMETER ShowInNewForm | |
If we want the field to be visible in the NewForm | |
.PARAMETER ShowInEditForm | |
If we want the field to be visible in the EditForm | |
.PARAMETER Hidden | |
If we want the fiels to be hidden from every form | |
.EXAMPLE | |
.\Set-FieldVisibility.ps1 -Field $Field -ShowInDisplayForm $true -ShowInNewForm $true -ShowInEditForm $true -Hidden $false | |
#> | |
function Set-FieldVisibility() { | |
Param( | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | |
[Microsoft.SharePoint.Client.Field] | |
$Field, | |
[Parameter(Mandatory=$false)] | |
[Bool]$ShowInDisplayForm = $true, | |
[Parameter(Mandatory=$false)] | |
[Bool]$ShowInNewForm = $true, | |
[Parameter(Mandatory=$false)] | |
[Bool]$ShowInEditForm = $true, | |
[Parameter(Mandatory=$false)] | |
[Bool]$Hidden = $false | |
) | |
Begin | |
{ | |
#----------------------------------------------------------------------- | |
# Getting if the parameters were specified to prevent updating unwanted values | |
#----------------------------------------------------------------------- | |
$showInDisplayFormSpecified = $PSBoundParameters.ContainsKey("ShowInDisplayForm") | |
$showInNewFormSpecified = $PSBoundParameters.ContainsKey("ShowInNewForm") | |
$showInEditFormSpecified = $PSBoundParameters.ContainsKey("ShowInEditForm") | |
$hiddenSpecified = $PSBoundParameters.ContainsKey("Hidden") | |
} | |
Process | |
{ | |
#----------------------------------------------------------------------- | |
# If the ShowInDisplayForm parameter has been specified, sets its value | |
#----------------------------------------------------------------------- | |
if($showInDisplayFormSpecified) | |
{ | |
$Field.SetShowInDisplayForm($ShowInDisplayForm) | |
} | |
#----------------------------------------------------------------------- | |
# If the ShowInNewForm parameter has been specified, sets its value | |
#----------------------------------------------------------------------- | |
if($showInNewFormSpecified) | |
{ | |
$Field.SetShowInNewForm($ShowInNewForm) | |
} | |
#----------------------------------------------------------------------- | |
# If the ShowInEditForm parameter has been specified, sets its value | |
#----------------------------------------------------------------------- | |
if($showInEditFormSpecified) | |
{ | |
$Field.SetShowInEditForm($ShowInEditForm) | |
} | |
#----------------------------------------------------------------------- | |
# If the Hidden parameter has been specified, sets its value | |
#----------------------------------------------------------------------- | |
if($hiddenSpecified) | |
{ | |
$Field.Hidden = $Hidden | |
} | |
#----------------------------------------------------------------------- | |
# Update the field | |
#----------------------------------------------------------------------- | |
$Field.Update() | |
#----------------------------------------------------------------------- | |
# Execute the query | |
#----------------------------------------------------------------------- | |
$Field.Context.ExecuteQuery() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment