I found a technet blog saying you could run c# code in powershell, so I ended up giving it a try. When I try to run the following powershell script I get 2 errors and I'm not sure how to resolve them. Does anyone know the fix for the errors below?
Technet Blog: Using CSharp (C#) code in Powershell scripts
Add-PSSnapin Microsoft.SharePoint.PowerShell
$Assem = {
"Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
}
$Source = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.IO;
namespace TurnAlertsOnOff
{
class onOff
{
static void Main(string[] args)
{
#code goes here.
}
}
}
"@
Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp
[TurnAlertsOnOff.onOff]::Main()
Error 1
Add-Type : Illegal characters in path.
At C:\Users\testUser\Desktop\test.ps1:115 char:1
+ Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.AddTypeCommand
Error 2 (Not caused by first error.)
Unable to find type [TurnAlertsOnOff.onOff]: make sure that the assembly containing this type is loaded.
At C:\Users\testUser\Desktop\test.ps1:117 char:1
+ [TurnAlertsOnOff.onOff]::Main()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (TurnAlertsOnOff.onOff:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound