Skip to main content

Notifications

Dynamics 365 general forum

Error creating new/retrieving existing WebResource via Powrshell

Posted on by 165

Hello.

I'm trying to use Dynamics SDK via Powershell, I tried to work with WebResources:
Here is my script:

<code>

$webResourcePat = "C:\Test\___default.html"

$wr = New-Object -TypeName Microsoft.Xrm.Sdk.Entity -ArgumentList "webresource"
$wr["name"] = $webResourceName;
$wr["displayname"] = $webResourceName;

$web_res_FileContent_Text = [IO.File]::ReadAllText("C:\Test\___default.html") 
$web_res_FileContent_bytes = [System.Text.Encoding]::Unicode.GetBytes($web_res_FileContent_Text)
$base64_web_res_content = [Convert]::ToBase64String($web_res_FileContent_bytes)
$wr["content"] = $base64_web_res_content

if (("C:\Test\___default.html").Contains(".htm"))
{
$wr["webresourcetype"] = New-Object -TypeName Microsoft.Xrm.Sdk.OptionSetValue -ArgumentList 1;
}
try
{
$id = $service.Create($wr); // !!!!!!!!!!!!!!! ERROR : Cannot find an overload for "Create" and the argument count: "1"
$publishXmlRequest += [string]::Concat("<webresource>", $id, "</webresource>"); 
Write-Host "Done!" -ForegroundColor Green -NoNewline; 
$publish = $true;
}
catch [Exception]
{ 
Write-Host "Failed! [Error : $_.Exception]" -ForegroundColor Red;
continue;
}

</code>

I Have error:
Cannot find an overload for "Create" and the argument count: "1".

How can I fix if ?
Thank you

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans