【发布时间】:2013-05-27 13:21:08
【问题描述】:
我想知道是否有可以将 c# 代码转换为 powershell cmdlet 代码的在线工具。我有以下代码,我需要拥有它的 powershell。我没有 Visual Studio 将其转换为 exe 或 dll。任何帮助或想法都会很棒。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace CopyUsersBetweenGroupsInSharepointByRR
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("This tool will copy the users from one group to another group");
Console.WriteLine("Please enter the URL of the site where your groups are available");
String siteUrl = Console.ReadLine();
using (SPSite site = new SPSite(siteUrl))
{
try
{
SPWeb web = site.OpenWeb();
Console.WriteLine("Please enter the name of the source group");
String sourceGroupName = Console.ReadLine();
Console.WriteLine("Please enter the name of the destination group");
String destinationGroupName = Console.ReadLine();
SPGroup sourceGroup = web.Groups[sourceGroupName];
SPGroup destinationGroup = web.Groups[destinationGroupName];
SPUserCollection sourceUsers = sourceGroup.Users;
SPUserInfo[] sourceUserInfoArray = new SPUserInfo[sourceUsers.Count];
for (int i = 0; i < sourceUsers.Count; i++)
{
sourceUserInfoArray[i] = new SPUserInfo();
sourceUserInfoArray[i].LoginName = sourceUsers[i].LoginName;
sourceUserInfoArray[i].Name = sourceUsers[i].Name;
}
destinationGroup.Users.AddCollection(sourceUserInfoArray);
destinationGroup.Update();
web.Update();
Console.WriteLine("Operation Completed Successfully");
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
}
}
}
【问题讨论】:
-
我想知道我的帖子有什么理由得到负面反馈。我只是想知道是否有另一种将 c# 转换为 powershell 的方法。由于突然合并,我们正处于严重的时间紧缩状态。对不起,如果我把帖子搞砸了。
-
这个工具好像叫@Sharken :)
-
@torres 我没有投反对票,但既然你问了,我想你可能会从回复中受益。通常,SO 社区认为“翻译我的代码”类型的帖子不是好问题。他们往往对提问者表现出很少的努力,过于本地化,并且很难让其他人学习。我怀疑您使用“是否有工具可以进行此翻译”的措辞被视为将“翻译我的代码”变成问题的肤浅尝试。
-
为什么会有这么多反对票?这个问题没问题。
标签: c# sharepoint powershell sharepoint-2010 cmdlets