string psc1 = @"filename";
if (File.Exists(psc1))
{
try
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(psc1);
string xpath = @"//PSConsoleFile/PSSnapIns";
string snapInValue = "Microsoft.Amalga.Management.PowerShell.AmalgaPSImaging";
XmlNode node = xdoc.CreateElement("PSSnapIn");
XmlAttribute attri = xdoc.CreateAttribute("Name");
attri.Value = snapInValue;
node.Attributes.Append(attri);
XmlNode nodeSnapIns = xdoc.SelectSingleNode(xpath);
nodeSnapIns.AppendChild(node);
xdoc.Save(psc1);
Console.WriteLine("AddImagingCmdlet successfully done");
}
catch (Exception e)
{
Console.WriteLine("AddImagingCmdlet end with error: /r/n/t{0}", e.Message);
Console.WriteLine("Please add /r/n/t<PSSnapIn Name=/"Microsoft.Amalga.Management.PowerShell.AmalgaPSImaging/"/> /r/ninto AmalgaPSShared.psc1 file manually.");
Console.WriteLine("Then press Enter to continue ...");
Console.ReadLine();
}
}
else
{
Console.WriteLine(psc1 + " NOT Exist.");
}