Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
133 lines (116 sloc) 5.3 KB
# Generated by: Sean McNellis (seanmcn)
#
# Copyright © Microsoft Corporation. All Rights Reserved.
# This code released under the terms of the
# Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)
# Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment.
# THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
# We grant You a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and distribute the object code form of the Sample Code, provided that.
# You agree:
# (i) to not use Our name, logo, or trademarks to market Your software product in which the Sample Code is embedded;
# (ii) to include a valid copyright notice on Your software product in which the Sample Code is embedded;
# and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against any claims or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the Sample Code
Function Get-CrmTransactionCurrencyId
{
param
(
[string]$ISOCode
)
# Get Transaction Currency by using ISO name
$tc = Get-CrmRecords -conn $conn -EntityLogicalName transactioncurrency -FilterAttribute isocurrencycode `
-FilterOperator eq -FilterValue $ISOCode -Fields transactioncurrencyid
if($tc.CrmRecords.Count -eq 1)
{
return $tc.CrmRecords[0].transactioncurrencyid
}
else
{
return $null
}
}
Function Update-CrmUserSettings
{
param
(
[PSObject]$User,
[Int]$AdvancedFindStartupMode,
[Int]$TimeZoneCode,
[Int]$PagingLimit,
[Int]$ReportScriptErrorOption,
[Int]$UILanguageId,
[int]$LocaleId,
[string]$TransactionCurrencyName
)
$fullName = $User.fullname
Write-Output "Update CRM user $fullName 's setting"
$userSetting = Get-CrmUserSettings -UserId $User.systemuserid -Fields *
$userSetting.advancedfindstartupmode = $AdvancedFindStartupMode
$userSetting.timezonecode = $TimeZoneCode
$userSetting.paginglimit = $PagingLimit
$userSetting.reportscripterrors = New-CrmOptionSetValue -Value $ReportScriptErrorOption
$userSetting.uilanguageid = $UILanguageId
$userSetting.uilanguageid = $LocaleId
$currencyId = Get-CrmTransactionCurrencyId -ISOCode $TransactionCurrencyName
Set-CrmUserSettings -CrmRecord $userSetting
# Set transaction currency separtely as it could be null.
if(($currencyId -ne $null))
{
$transactionCurrency = New-CrmEntityReference -EntityLogicalName transactioncurrency -Id $currencyId
Set-CrmRecord -conn $conn -EntityLogicalName usersettings -Id $User.systemuserid `
-Fields @{"transactioncurrencyid"=$transactionCurrency}
}
}
# Script parameters #
$crmAdminUser = "<CRM admin account. i.e.) administator@contoso.onmicrosoft.com>"
$crmAdminPassword = ConvertTo-SecureString -String "<password>" -AsPlainText -Force
# Blank following parameters if you use Online environment.
$organizationName = "<organization name> i.e.) contoso>"
$serverUrl ="<CRM Server URL i.e.) http://crmserver:5555>"
# CrmUserSettings parameters. Use Get-CrmUserSettings command to get and display all parameters
# 1-Simple
# 2-Advanced
$advancedFindStartupMode = 2
# Use Get-CrmTimeZones to retrieve all TimeZones information
$timeZoneCode = 235
# You can speficy 25,50,75,100,250
$pagingLimit = 50
# 1-Ask me for permission to send an errro report to Microsoft
# 2-Automatically send an error report to Microsoft without asking me for permission
# 3-Never sent an error report to Microsoft about Microsoft Dynamics CRM
$reportScriptErrorOption = 2
# You need to provision language pack before setting this.
$uiLanguageId = 1033
# Specify LocalId which update formatting setting
$localeId = 1033
# Specify Currency ISO Code
$transactionCurrencyName = "USD"
# Script parameters #
Write-Output "Connecting to CRM Online as $crmAdminUser"
$crmCred = New-Object System.Management.Automation.PSCredential ($crmAdminUser,$crmAdminPassword)
try
{
# You can also use Get-CrmConnection to directly create connection.
# See https://msdn.microsoft.com/en-us/library/dn756303.aspx for more detail.
if($organizationName -eq "")
{
Connect-CrmOnlineDiscovery -Credential $crmCred -ErrorAction Stop
}
else
{
$global:conn = Get-CrmConnection -OrganizationName $organizationName -ServerUrl $serverUrl -Credential $crmCred -ErrorAction Stop
}
}
catch
{
throw
}
Write-Output "Retrieve all active users"
# if you want to filter more, user Get-CrmRecordsByFetch or Get-CrmRecordsByViewName
$users = Get-CrmRecords -EntityLogicalName systemuser -FilterAttribute isdisabled -FilterOperator eq -FilterValue $false -Fields systemuserid,fullname
Write-Output "Update CRM user setting"
$users.CrmRecords | % {Set-CrmUserSettings -User $_ -AdvancedFindStartupMode $advancedFindStartupMode `
-TimeZoneCode $timeZoneCode -PagingLimit $pagingLimit -ReportScriptErrorOption $reportScriptErrorOption `
-UILanguageId $uiLanguageId -LocaleId $localeId -TransactionCurrencyName $transactionCurrencyName `
}
Write-Output "Completed"