The C# code below will invoke the above PowerShell script:
public string CreateMailbox(Int64 requestID, int sID, string cName, string firstName, string lastName, string displayName, string UPN, string alias, string exchangeDatabase, string userName, string OU, string accountPassword)
Uri uri = new Uri(exch.ExchangeServer);
SecureString secureExchangePassword = String2SecureString(exch.ExchangePassword);
PSCredential credentials = new PSCredential(exch.ExchangeUserName, secureExchangePassword);
Runspace runspace = RunspaceFactory.CreateRunspace();
Collection<PSObject> results = new Collection<PSObject>();
PowerShell powershell = PowerShell.Create();
powershell.Runspace = runspace;
//Change the Path to the Script to suit your needs
System.IO.StreamReader sr = new System.IO.StreamReader("Script\\MailboxScript.ps1");
results = powershell.Invoke();
if (powershell.Streams.Error.Count > 0)
StringBuilder sb = new StringBuilder();
foreach (ErrorRecord er in powershell.Streams.Error)
sb.Append(er.ToString() + " ");
LogFactory.LogError("RequestID:'" + requestID.ToString() + "' ID:'" + sID.ToString() + "' Error: On creating exchange account(PowerShell). Reason: " + sb.ToString());
return String.Concat("CN=" + cName + ",", OU);
catch (Exception ex)
LogFactory.LogError("RequestID:'" + requestID.ToString() + "' ID:'" + sID.ToString() + "' Error: While creating exchange account. Reason: " + ex.Message.ToString());
runspace = null;
private SecureString String2SecureString(string password)
SecureString remotePassword = new SecureString();
for (int i = 0; i < password.Length; i++)
This C# code can be called from an Application passing the required Exchange Server information and required Parameter values. The using statements in the C# code mentions the required Nuget packages to be installed.
Geckodriver is an executable that interacts with Firefox installed on the System to run automated tests by running the Firefox instance either fully or in ghost-mode. Geckodriver creates profiles in the Windows temp folder that can be of huge size depending on the Profile created for the Firefox driver. The folder name is of the format “rust_mozprofile*”.
The following Powershell script will delete such folders by searching for this string format under C:\windows\temp and also creates logs for the deleted folders.
First, you need to access the mailbox on the Microsoft Exchange Server and then get the mailbox statistics for the count of e-mails. The credentials you use should have admin access on the Server to be able to access the mailbox.
The following script uses some credentials stored in a file on the machine where the script is running and connects to a Session on the Microsoft Exchange Server:
The scripts to be executed are present at the location C:\Scripts with extension “.sql”. The password can be also passed as an argument to the PowerShell script and added to the Release Definition secret variable.
Use the Triggers tab to link to the required Build definition of your Project so that the Release definition is integrated with the Build pipeline. The linking can also be done using the Artifacts tab.
You can setup multiple environments using this strategy like Dev, POC and Production.
Suppose you need to hide the password in your clear text connection strings at a particular back-up path or any other path in config files. This can be achieved using PowerShell with the following code.
Today, one of the users of my application wanted to know if we can find out the original title of a ticket created in the Application. Although, we do not store any such logs for modifications, while on the verge of giving up, I remembered we archive the e-mails received by the Windows Service application that processes the e-mails and archives them at a location on the Server on which it is installed. The e-mail Subject line is stored as the ticket title. These tickets which are created by the Windows Service can be viewed in the Web Application.
Since the folder with the archiving e-mails have a lot of ’em, simply doing a Windows Search is a time killer! So I remembered my way through the good old DOS commands.
Since the .eml file has the ticket number, I used the dir command to search for the e-mail name and copy command to copy it to another location quickly.
Firstly cd to the location where the archived e-mails are stored on the Server:
So e.g. if the ticket number is 123456
dir *123456* /s
The /s searches for the File name inside the two wildcard characters asterisk “*” with the dir command.
Then if the file name is e.g. TICKET123456 – abc.eml then use copy command as follows within the same directory:
copy "TICKET123456 - abc.eml" c:\Temp
So, with the e-mail having the original Subject Line preserved, I could share the original ticket title.