0

Backgroud: I work as a Senior System Admin for my company. I'm quite novice when it comes to Powershell and Bash but have 0 experience in Web development. I am familiar with OOP in general.

Requirements: Users need access to very specific tasks on remote Win servers like running certain Scheduled Tasks, checking certain URLs, recycling IIS app pools etc. All is easily scripted using Powershell. Rather than giving the users direct access to the scripts, mask everything behind a Web Portal. Then after authenticating using LDAP, the user is presented with a set of pre-setup scripts he\she can run directly from the portal.

Challenge: Do this all by myself without prior programming experience.

Problem: Where do I start? Do I begin learning C# first? ASP .NET? MVC? Javascript? HTML? I'm rather lost and would appreciate some general guidance.

2 Answers 2

1

I am .Net Developer, once i had task to make MVC UI interact with Microsoft Exchange server and manage Mailboxes of AD users, i had to learn powershell and how to interact with powershell through C#. So based on my experience i will advise you to start learning C# Using Console Application, understand how c# works with Powershell and AD and than start learning MVC to build an UI.

You should install System.management.Automation package from NuGet Package manager.

C# => Powershell (Execute Powershell Command) => Microsoft Exchange.

Simple Sample, getting user PrimarySmtpAddress attribute.

using System.Management.Automation;
using System.Management.Automation.Runspaces;

private static WSManConnectionInfo _connectionInfo;

static void Main(string[] args)
{
    string userName = "DOMAIN\\User";
    string password = "UserPassowrd";
    PSCredential psCredential = new PSCredential(userName, GenerateSecureString(password));

    _connectionInfo = new WSManConnectionInfo(
            new Uri("http://server.domain.local/PowerShell"),
            "http://schemas.microsoft.com/powershell/Microsoft.Exchange", psCredential);
    _connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;

    Console.WriteLine(GetPrimarySmtpAddressBy("Firstname Lastname");
}

public static string GetPrimarySmtpAddressBy(string identity)
    {
        using (Runspace runspace = RunspaceFactory.CreateRunspace(_connectionInfo))
        {

            using (PowerShell powerShell = PowerShell.Create())
            {
                powerShell.AddCommand("Get-Mailbox");
                powerShell.AddParameter("Identity", identity);
                runspace.Open();

                powerShell.Runspace = runspace;

                PSObject psObject = powerShell.Invoke().FirstOrDefault();

                if (psObject != null && psObject.Properties["PrimarySmtpAddress"] != null)
                    return psObject.Properties["PrimarySmtpAddress"].Value.ToString();
                else return "";
            }
        }
    }

public static System.Security.SecureString GenerateSecureString(string input)
    {
        System.Security.SecureString securePassword = new System.Security.SecureString();
        foreach (char c in input)
            securePassword.AppendChar(c);
        securePassword.MakeReadOnly();

        return securePassword;
    }
Sign up to request clarification or add additional context in comments.

Comments

1

Take a look on Powershell Web Access. Maybe this is an approach to avoid the learning of all the technologies you mention.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.