I’ve written a custom method in C# and I’m trying to use it in a powershell function, the issue I’m seeing at this point is, I’m using an assembly that I had to reference in VS and I’m not sure how to make a reference to it, properly, in powershell.
$Assem = ("C:\Delimon.Win32.IO\Delimon.Win32.IO.dll, Version=4.0.4764.1936, Culture=neutral, PublicKeyToken=6f601db60ebd9657") $Source = @" using System; using System.Collections.Generic; using Delimon.Win32.IO; namespace LongFileExt { public class Truncate { public static List Extension(string originalPath, int extLength) { // Only get files that begin with the letter "c." string[] dirs = Directory.GetFiles(originalPath, "*.*", SearchOption.AllDirectories); List returnValue = new List(); foreach (string dir in dirs) { string ext = Path.GetExtension(dir); int extCount = ext.Length; if (extCount > 4) { string baseName = Path.GetFileNameWithoutExtension(dir); string fileName = Path.GetFileName(dir); string path = dir.Substring(0, dir.LastIndexOf(("\\"))); string newExt = ext.Substring(1, extLength); string newFileName = path + "\\" + baseName + "." + newExt; if (File.Exists(dir)) { File.Move(dir, newFileName); } returnValue.Add(newFileName + ", " + baseName); } } return returnValue; } } } "@ Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp [LongFileExt]::Truncate($exportPath,$extLength)
And I am getting the following error:
Add-Type : Could not load file or assembly 'C:\\Delimon.Win32.IO\\Delimon.Win32.IO.dll\, Version\=4.0.4764.1936\, Culture\=neutral\, PublicKeyToken\=6f601db60ebd9657' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) At line:86 char:1 + Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand