Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LightSwitch: Modifying roles, permissions and users via PowerShell

Miscellaneous Scripts

d-fens GmbH General-Guisan-Strasse 6 CH-6300 Zug Switzerland

# LightSwitch: Modifying roles, permissions and users via PowerShell
# http://d-fens.ch/2014/04/18/lightswitch-modifying-roles-permissions-and-users-via-powershell/
$perm = $sec.Permissions |? Id -eq 'Microsoft.LightSwitch.Security:SecurityAdministration';
$r = $sec.Roles |? Name -eq 'DefaultUser';
$rp = New-Object LsWrapper.SecurityData.RolePermission;
$sec.AddToRolePermissions($rp);
$sec.SetLink($rp, 'Role', $r);
$sec.SetLink($rp, 'Permission', $perm);
$sec.UpdateObject($rp);
$sec.SaveChanges();
<#
Copyright 2014-2015 d-fens GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#>
# LightSwitch: Modifying roles, permissions and users via PowerShell
# http://d-fens.ch/2014/04/18/lightswitch-modifying-roles-permissions-and-users-via-powershell/
PS > Add-Type -Path "C:\dfch.biz\LsWrapper.dll";
PS > $sec = New-Object LsWrapper.SecurityData.SecurityData(
'https://www.example.com/Microsoft.LightSwitch.SecurityData.svc');
PS > $sec.Credentials = [System.Net.CredentialCache]::DefaultCredentials;
PS > $sec | gm -Type Properties;
Name MemberType Definition
---- ---------- ----------
Permissions Property System.Data.Services.Client.DataServiceQuery[LsWrapper...
RoleAssignments Property System.Data.Services.Client.DataServiceQuery[LsWrapper...
RolePermissions Property System.Data.Services.Client.DataServiceQuery[LsWrapper...
Roles Property System.Data.Services.Client.DataServiceQuery[LsWrapper...
<#
Copyright 2014-2015 d-fens GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#>
Miscellaneous Scripts
Copyright 2014 d-fens GmbH
This product includes software developed at
d-fens GmbH (http://d-fens.ch/)
d-fens GmbH
General-Guisan-Strasse 6
CH-6300 Zug
Switzerland
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment