< Back
New-CrmRecord
Post
NAME New-CrmRecord
SYNOPSIS
Creates a new CRM record by specifying field name/value set, and returns record guid.
SYNTAX
New-CrmRecord [-conn <CrmServiceClient>] [-EntityLogicalName] <String> [-Fields] <Hashtable> [<CommonParameters>]
New-CrmRecord [-conn <CrmServiceClient>] [-CrmRecord] <PSObject> [[-PreserveCrmRecordId] <SwitchParameter>]
[<CommonParameters>]
DESCRIPTION
The New-CrmRecord cmdlet lets you create a record to your CRM organization.
Use @{"field logical name"="value"} syntax to create Fields, and make sure you specify correct type of value for
the field.
You can use Get-CrmEntityAttributeMetadata cmdlet and check AttributeType to see the field type. In addition, for
CRM specific types, you can use New-CrmMoney, New-CrmOptionSetValue or New-CrmEntityReference cmdlets.
PARAMETERS
-conn <CrmServiceClient>
A connection to your CRM organization. Use $conn = Get-CrmConnection <Parameters> to generate it.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-EntityLogicalName <String>
A logicalname for an Entity to create. i.e.) account, contact, lead, etc..
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Fields <Hashtable>
A List of field name/value pair. Use @{"field logical name"="value"} syntax to create Fields, and make sure
you specify correct type of value for the field.
You can use Get-CrmEntityAttributeMetadata cmdlet and check AttributeType to see the field type. In addition,
for CRM specific types, you can use New-CrmMoney, New-CrmOptionSetValue or New-CrmEntityReference cmdlets.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-CrmRecord <PSObject>
A record object which is obtained via Get-CrmRecord/Get-CrmRecords. When you pass CrmRecord, then you don't
use EntityLogicalName/Fields
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-PreserveCrmRecordId [<SwitchParameter>]
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
-------------------------- Example 1 --------------------------
New-CrmRecord -conn $conn -EntityLogicalName account -Fields @{"name"="account name";"telephone1"="555-5555"}
This example creates an account record and set value for account and telephone1 fields.
Guid
----
57bd1c45-2b17-e511-80dc-c4346bc4fc6c
-------------------------- Example 2 --------------------------
New-CrmRecord account @{"name"="account name";"industrycode"=New-CrmOptionSetValue -Value 1}
This example creates an account record by specifying OptionSetValue to IndustryCode field by omitting parameter
names.
When omitting parameter names, you do not provide $conn, cmdlets automatically finds it.
Guid
----
57bd1c45-2b17-e511-80dc-c4346bc4fc6c
-------------------------- Example 3 --------------------------
New-CrmRecord account @{"name"="account name";"overriddencreatedon"=[datetime]"2000-01-01"}
This example creates an account record by specifying past date for CreatedOn. You can create DateTime object by
casting like this Example or use Get-Date cmdlets.
Guid
----
57bd1c45-2b17-e511-80dc-c4346bc4fc6c
-------------------------- Example 4 --------------------------
PS C:\\>$parentId = New-CrmRecord account @{"name"="parent account name"}
PS C:\\>$parentReference = New-CrmEntityReference -EntityLogicalName account -Id $parentId
PS C:\\>$childId = New-CrmRecord account @{"name"="child account name";"parentaccountid"=$parentReference}
This example creates an account record, then assign the created account as Parent Account field to second account
record.
Guid
----
59bd1c45-2b17-e511-80dc-c4346bc4fc6c
-------------------------- Example 5 --------------------------
PS C:\\>$account = Get-CrmRecord -conn $conn -EntityLogicalName account -Id $accountid -Fields *
PS C:\\>New-CrmRecord -conn $conn -CrmRecord $account
This example get record by Get-CrmRecord, then pass it to New-CrmRecord to create another record.
Guid
----
d6960250-d178-e711-80ff-c4346bdc42d1
RELATED LINKS
SYNOPSIS
Creates a new CRM record by specifying field name/value set, and returns record guid.
SYNTAX
New-CrmRecord [-conn <CrmServiceClient>] [-EntityLogicalName] <String> [-Fields] <Hashtable> [<CommonParameters>]
New-CrmRecord [-conn <CrmServiceClient>] [-CrmRecord] <PSObject> [[-PreserveCrmRecordId] <SwitchParameter>]
[<CommonParameters>]
DESCRIPTION
The New-CrmRecord cmdlet lets you create a record to your CRM organization.
Use @{"field logical name"="value"} syntax to create Fields, and make sure you specify correct type of value for
the field.
You can use Get-CrmEntityAttributeMetadata cmdlet and check AttributeType to see the field type. In addition, for
CRM specific types, you can use New-CrmMoney, New-CrmOptionSetValue or New-CrmEntityReference cmdlets.
PARAMETERS
-conn <CrmServiceClient>
A connection to your CRM organization. Use $conn = Get-CrmConnection <Parameters> to generate it.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-EntityLogicalName <String>
A logicalname for an Entity to create. i.e.) account, contact, lead, etc..
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Fields <Hashtable>
A List of field name/value pair. Use @{"field logical name"="value"} syntax to create Fields, and make sure
you specify correct type of value for the field.
You can use Get-CrmEntityAttributeMetadata cmdlet and check AttributeType to see the field type. In addition,
for CRM specific types, you can use New-CrmMoney, New-CrmOptionSetValue or New-CrmEntityReference cmdlets.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-CrmRecord <PSObject>
A record object which is obtained via Get-CrmRecord/Get-CrmRecords. When you pass CrmRecord, then you don't
use EntityLogicalName/Fields
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-PreserveCrmRecordId [<SwitchParameter>]
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
-------------------------- Example 1 --------------------------
New-CrmRecord -conn $conn -EntityLogicalName account -Fields @{"name"="account name";"telephone1"="555-5555"}
This example creates an account record and set value for account and telephone1 fields.
Guid
----
57bd1c45-2b17-e511-80dc-c4346bc4fc6c
-------------------------- Example 2 --------------------------
New-CrmRecord account @{"name"="account name";"industrycode"=New-CrmOptionSetValue -Value 1}
This example creates an account record by specifying OptionSetValue to IndustryCode field by omitting parameter
names.
When omitting parameter names, you do not provide $conn, cmdlets automatically finds it.
Guid
----
57bd1c45-2b17-e511-80dc-c4346bc4fc6c
-------------------------- Example 3 --------------------------
New-CrmRecord account @{"name"="account name";"overriddencreatedon"=[datetime]"2000-01-01"}
This example creates an account record by specifying past date for CreatedOn. You can create DateTime object by
casting like this Example or use Get-Date cmdlets.
Guid
----
57bd1c45-2b17-e511-80dc-c4346bc4fc6c
-------------------------- Example 4 --------------------------
PS C:\\>$parentId = New-CrmRecord account @{"name"="parent account name"}
PS C:\\>$parentReference = New-CrmEntityReference -EntityLogicalName account -Id $parentId
PS C:\\>$childId = New-CrmRecord account @{"name"="child account name";"parentaccountid"=$parentReference}
This example creates an account record, then assign the created account as Parent Account field to second account
record.
Guid
----
59bd1c45-2b17-e511-80dc-c4346bc4fc6c
-------------------------- Example 5 --------------------------
PS C:\\>$account = Get-CrmRecord -conn $conn -EntityLogicalName account -Id $accountid -Fields *
PS C:\\>New-CrmRecord -conn $conn -CrmRecord $account
This example get record by Get-CrmRecord, then pass it to New-CrmRecord to create another record.
Guid
----
d6960250-d178-e711-80ff-c4346bdc42d1
RELATED LINKS