Functions/Entity/New-CdsEntity.ps1
<#
.SYNOPSIS Initialize Entity object instance. #> function New-CdsEntity { [CmdletBinding()] [OutputType("Microsoft.Xrm.Sdk.Entity")] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $LogicalName, [Parameter(Mandatory = $false)] [ValidateNotNullOrEmpty()] [Guid] $Id ) begin { $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); } process { $record = New-Object -TypeName "Microsoft.Xrm.Sdk.Entity" -ArgumentList $LogicalName; if($Id) { $record.Id = $Id; } $record; } end { $StopWatch.Stop(); Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch; } } Export-ModuleMember -Function New-CdsEntity -Alias *; Register-ArgumentCompleter -CommandName New-CdsEntity -ParameterName "LogicalName" -ScriptBlock { param($CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters) $validLogicalNames = Get-CdsEntitiesLogicalName; return $validLogicalNames | Where-Object { $_ -like "*$wordToComplete*"}; } |