Microsoft.Xrm.Data.Powershell: PowerShell for Dynamics CRM Organization Data

These PowerShell functions are for Dynamics CRM data operations such as CRUD and manipulating User and System Settings. This module depends on XrmTooling version 7.1.1.6680 or higher but functions on Dynamics CRM Online and 2013, 2015 versions.

 
 
 
 
 
4.8 Star
(10)
4,546 times
Add to favorites
11/9/2015
E-mail Twitter del.icio.us Digg Facebook
  • Problems get user status
    2 Posts | Last post November 20, 2019
    • For some reason I am not getting anything returned when querying for a users isdisabled status. My current code ism as follows:
      The guts of the script is:
      $xcrmConn = Connect-CrmOnPremDiscovery -Credential $me -ServerUrl $CRM_URL -OrganizationName $CRM_ORG
      $userObject = Get-CrmRecords -conn $xcrmconn -EntityLogicalName systemuser -FilterOperator eq -FilterAttribute domainname -FilterValue "$user" -Fields *
      $userStatus = $userObject.CrmRecords.isdisabled
      The $userStatus variable comes out as null.
      The connection to CRM is opening up correctly and I am using admin account to run the script.
      Your help would be appreciated.
    • Hi,
      I solved it as it appears there was actually an issue with the $user variable I was passing in so the code was working as it was unable to find the user.
  • SharePoint Integration
    1 Posts | Last post July 10, 2017
    • Kenichiro
      
      Is there any methods to obtain information about content stored in a SharePoint library in your powershell or in the XRMTooling?
      
      I have a client that wants a SharePoint Document library tied to CRM to have permissions corrected to mirror what is in CRM.
      
      Any insight you can provide would be insightful!
  • How to set Team Admins?
    1 Posts | Last post March 29, 2017
    • Cross posting from https://community.dynamics.com/crm/f/117/t/231885
      
      get-crmrecords -entitylogicalname team" shows the administratorid as the team admin.  I need to alter these via script, but when I do:
      set-crmrecord -entitylogicalname team -id <team guid> -fields @{administratorid = "Name"}
      I get the following error: 
      System.InvalidCastException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #7537B7EB
      At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.Xrm.Data.PowerShell\Microsoft.Xrm.Data.Powershell.psm1:758 char:9
      +         throw $conn.LastCrmException
      +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : OperationStopped: (:) [], FaultException`1
          + FullyQualifiedErrorId : System.InvalidCastException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #7537B7EB
  • Problems executing workflows via remote powershell
    1 Posts | Last post March 15, 2017
    • Using the Invoke-CrmRecordWorkflow powershell command on two different tenants. The first tenant works correctly and invokes the workflow.
      
      The second tenant appears to call the workflow, and the powershell command returns no errors, however on the tenant where the command is successful the Invoke-CrmRecordWorkflow command returns a GUID. On the tenant where the command fails it returns a GUID value of 00000000-0000-0000-0000-000000000000. Is there some specific CRM setting that is preventing this?
      
      
  • Commands not recognised
    2 Posts | Last post March 03, 2017
    • I'monly able to get through the first couple of steps. 
      
      Ran "Import-Module Microsoft.Xrm.Data.Powershell" which returned no error or any other response. Not sure if I was expecting some kinds or message response.
      
      Rhen ran "Connect-CrmOnlineDiscovery -InteractiveMode" which returns an error:
      
      Get-CrmConnection : The term 'Get-CrmConnection' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
      At C:\Users\SiN\Documents\WindowsPowerShell\Modules\Microsoft.Xrm.Data.Powershell\Microsoft.Xrm.Data.Powershell.psm1:50 char:24
      +         $global:conn = Get-CrmConnection -InteractiveMode -Verbose
      +                        ~~~~~~~~~~~~~~~~~
          + CategoryInfo          : ObjectNotFound: (Get-CrmConnection:String) [], CommandNotFoundException
      
      Any idea what I'm missing here?
    • Nevermind this one. I was trying to run the commands on the Powershell CMD but when I tried from the ISE it worked perfectly fine.
  • Add team membership to a user
    2 Posts | Last post September 30, 2016
    • Hi All,
      could you please hint me with the idea if it's possible to add a team to a user (so that user had a couple of teams aligned, not just the default one from Busines unit).
      
      Thank you in advance.
    • I was actually trying to do that by 
      
      $sql_fin_protected=@"
      select teamid from  TeamBase where Name='Financial Protected Team'
      "@
      
      
      $NewSequenceID = invoke-sqlcmd -ServerInstance "localhost" -Database "Elite_mscrm" -Query $sql_fin_protected
      $teamid_fin_protected=$NewSequenceID.teamid.ToString()
      
      $user='Someuser'
      $sql=@"
      declare @domname AS VARCHAR(100)
      set @domname='$domain\$user'
      select systemuserid from SystemUser where domainname=@domname
      "@
      $NewSequenceID = invoke-sqlcmd -ServerInstance "localhost" -Database "Elite_mscrm" -Query $sql
      $userid=$NewSequenceID.systemuserid.ToString()
      Add-CrmRecordAssociation -EntityLogicalName1 team -Id1 $teamid_fin_protected -EntityLogicalName2 systemuser -id2 $userid -RelationshipName teammembership_association
      
      But it doesn't look like doing the job.... probably I was doing something wrong
      
  • implement wildcard ?
    1 Posts | Last post September 05, 2016
    • Hi Kenichiro,
      
      I came across your module.
      Am I the only one who absolutely cannot work with this module?
      The commands are really special and not like all the other modules.
      One huge disadvantage is that I can't use a * in simple commands like
      
      Get-CrmRecord -EntityLogicalName account -Fields * -Id * -conn $conn
      
      This really is annoying. It's a good approach but can you implement basic stuff like wildcard or make the values accept from pipelines?
      
      I really would appreciate it.
      
      regards,
  • How to run a workflow using Microsoft.Xrm.Data.Powershell
    1 Posts | Last post August 17, 2016
    • Hi Kenichiro,
      
      I try to start a workflow with name "Workflow Test" on activitytest
      
      Invoke-CrmRecordWorkflow  -conn $conn -CrmRecord $activitytest -WorkflowName "Workflow Test"
      
      $activitytest get the right record using Get-CrmRecord
      Invoke-CrmRecordWorkflow returns Guid.Empty and the "Workflow Test" was not started and executed
  • Large Queries
    2 Posts | Last post July 11, 2016
    • Hi,
      Is there a way to use this framework to retrieve large datasets (more than 5000 records) using the get-crmrecords and/or get-crmrecordsbyfetch commandlets? Thanks.
    • Hi,
      I just wanted to say that after reviewing your help files more closely for these commandlets in this framework I was able to solve my problem. Thanks!
  • Importing Managed Solutions
    1 Posts | Last post April 27, 2016
    • Hi Ken,
      
      We are using the script to automate the process of importing managed solutions but encountered a few issues:
      * Customizations on OTB forms are not being affected - we changed the default value of an optionset and it is not affected after the import completes, this is an otb entity with an otb optionset
      * Workflows are not taking changes - we have made modifications on workflows but the changes don't take when the import completes, do they need to be deactivated before importing the solution
      * Ribbon button's are not updating - we added a few custom ribbon buttons on the solution and updated them to include display rules.  After the solution imports the XML does not show these display rules.
      
      We have tried running the command in the following manner:
       Import-CrmSolution -conn $orgConnection -SolutionFilePath $filePath -ActivatePlugIns -OverwriteUnmanagedCustomizations -MaxWaitTimeInSeconds 7200
      AND
       Import-CrmSolution -conn $orgConnection -SolutionFilePath $filePath -ActivatePlugIns -OverwriteUnmanagedCustomizations $true -MaxWaitTimeInSeconds 7200
      
      Have you encountered these issues before?  
1 - 10 of 17 Items