Powershell error loading dlls

I have a powershell script where I load some sharepoint assemblies. It works on my machine but when I zip it up with the dlls and send it to my friend. He puts the dlls in the correct place and then runs the script and we get this error:

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
Could not load file or assembly ‘
Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll’ or one o
f its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131
515)

We have the same version of powershell

add the dlls like so

Try{
Add-Type -Path ‘C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll’
Add-Type -Path ‘C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll’
Add-Type -Path ‘C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Publishing.dll’
Add-Type -Path ‘C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll’
}

catch {
Write-Host $_.Exception.Message
Write-Host “No further parts of the migration will be completed, The script will now exit”
Exit
}

=================

  

 

do they have SharePoint installed? if yes then they dont need these assemblies in zip becuase these will be on his machine.
– Waqas Sarwar MCSE
Jun 10 ’15 at 15:12

=================

1 Answer
1

=================

their two things.

Not using SharePoint Client Components?

Set the execution policy unrestricted
Make sure that the assembly hasn’t been blocked, right click > properties
PowerShell supports a config file which by default is not present.by default, it ought to be created here: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.config

Using SharePoint Client Components?
If you are adding the SharePoint Client assemblies required for the execution of CSOM requests then you should take a different approach. Rather than bundling these assemblies with your script, instead insure that the correct SharePoint Client Components package is installed on the executing machine and reference the assemblies from their default location:

Download Client Components:

SharePoint Online Client Components
SharePoint 2013 Client Components

Reference Accordingly:

C:\Program Files\Common Files\microsoft shared\Web Server
Extensions\16\ISAPI\assembly.dll
C:\Program Files\Common Files\microsoft shared\Web Server
Extensions\15\ISAPI\assembly.dll

PowerShell Add-Type Error: Could not load file or assembly XXX or one of its dependencies.