Powershell generic session and import this session in Exchange remote management session c#

The situation :
I am trying to make an application (c#-asp.net) to manipulate user's on an exchange server. The application will be on a different server than the exchange's one. So, to manipulate the data, I am using an "Exchange remote management session" created
with c#. Exchange remote management session give access to simple powershell command like "New-Mailbox" and "Set-User" - This is good for simple task, but in my case, I have to do more complexe operations that will need some specific command
that is not included in the default command. To access this command, I have to use some specific module like "ActiveDirectory". It is simple ? Only use "Import-Module" ! Not really, like I said, the "Exchange remote management session"
is very limited with the command, and "Import-Module" is not allowed...
So what we can do ?
I read a lot about my problem, and the most "simple" (That I understand the theory) solution is something like :
Start with a generic PS session, import the AD module, then connect to an Exchange management session and do an Import-PSSession and use implicit remoting for the
Exchange management stuff.
Given that I am pretty new to manipulate the Powershell with c#, I have no idea how to use this awesome solution in my code. So I am asking your help.
Here's my current code :
// Prepare the credentials.
string runasUsername = @"MarioKart 8";
string runasPassword = "MarioKart";
SecureString ssRunasPassword = new SecureString();
foreach (char x in runasPassword)
ssRunasPassword.AppendChar(x);
PSCredential credentials =
new PSCredential(runasUsername, ssRunasPassword);
// Prepare the connection
var connInfo = new WSManConnectionInfo(
new Uri("MarioKart8Server"),
"http://schemas.microsoft.com/powershell/Microsoft.Exchange",
credentials);
connInfo.AuthenticationMechanism =
AuthenticationMechanism.Basic;
connInfo.SkipCACheck = true;
connInfo.SkipCNCheck = true;
// Create the runspace where the command will be executed
var runspace = RunspaceFactory.CreateRunspace(connInfo);
// create the PowerShell command
var command = new Command("New-Mailbox");
// Add the command to the runspace's pipeline
runspace.Open();
var pipeline = runspace.CreatePipeline();
pipeline.Commands.Add(command);
// Execute the command
var results = pipeline.Invoke();
if (results.Count > 0)
System.Diagnostics.Debug.WriteLine("SUCCESS");
else
System.Diagnostics.Debug.WriteLine("FAIL");
This code work great for simple task (like "New-Mailbox") ! But how can I create a "generic PS session" and then use this session in the "Exchange remote management session" ?

Hi Vincent,
Generally we can use the cmdlet "import-module" to import the AD module on DC (Domain Controller), and we can also create a exchange remote powershell session with the cmdlet new-pssession, for more detailed information to create exchange remote session,
please refer to this article:
Managing Exchange 2010 with Remote PowerShell
In addition, to invoke powershell cmdlet in C#, please also try to save all the cmdlets to a powershell script (.ps1 file), then we can add the powershell script to C# like:
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(scriptText);
If I have any misunderstanding, please let me know.
Best Regards,
Anna Wang

Similar Messages

  • Is it possible to export contacts  from Outlook 2011 for Mac and importing this file back into Mac Address Book.? please reply me its urgent

    Is it possible to export contacts  from Outlook 2011 for Mac and importing this file back into Mac Address Book.? please reply me its urgent

    Is it possible to export contacts  from Outlook 2011 for Mac and importing this file back into Mac Address Book.? please reply me its urgent

  • HT1364 Move itunes library from a windows computer and import this library to itunes on a macbook air

    Is it possible to move itunes library from a windows computer to an external drive (time capsule) while, keeping all the playlist, ratings, plays etc. And importing this library to itunes on a macbook air? And how is it done? The media files should stay on the external drive since there is not enough space on the macbook air.
    Regards
    Søren

    Hey man. Thanks a lot for the reply (hold the options instead of command key while launching). My old itunes library is now on my new computer in itunes, but the mp3 files are not in the same itunes folder. Where do I place these or what do I do to play them in my new itunes library?
    All the songs in the library have exclamation marks in front of them because itunes can't find them.
    Thanks again
    Søren

  • Writing XML from java and import this into OpenOffice

    Hello , i'd like to write a XML file which covers Text and Images and can be imported into OpenOffice. The Export to XML already works. But i don't know what XSL or other files a necessary ? Does anyone have a converter ? Or can gibe a clue ?

    dunno if it is feasable with only an XML file.
    i am doing this by generating an SXW file (OpenOffice) using JAXP for the XML content and java.util.zip to pack the XML and the images in the SXW.

  • Export and import a table data

    Hi All,
    There is table abc which is having appprox 40lak records without partitions(and have dmp of this data). Due to space constraints I want to compress the data and put it in archive schema.
    My question is:
    1) Can we import the data into other schema(say: archive schema) in compressed mode. If so could you please let me know the syntax for that.
    2) Can we import the data into some temporary table(say: temp) in same schema?
    3) And if any blob column exists in table then can we import the data without this blob column data.(Supposing the export dump has the blob data).
    Is it possible, or whould we export without this blob column and import this to other table?
    Please help me out.
    Edited by: user11942774 on 4 Dec, 2011 10:33 PM

    Thanks Mahir,
    Could you please let me know the syntax or with any examples if possible.
    is it possible to drop any column say blob column after the table is in compressed mode?
    Edited by: user11942774 on 4 Dec, 2011 10:53 PM
    Edited by: user11942774 on 4 Dec, 2011 10:54 PM

  • Microsoft Exchange Health Manager worker process (15200) received restart request and will be stopped. Server 2013

    Hi everyone,
    Anyone seen this before? The Health Manager seems te stop and restart rapidly.
    Microsoft Exchange Health Manager worker process (15200) received restart request and will be stopped. Restart reason: Unknown. 
    Error message: 
    System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
       at System.Diagnostics.Eventing.Reader.EventLogException.Throw(Int32 errorCode)
       at System.Diagnostics.Eventing.Reader.NativeWrapper.EvtSubscribe(EventLogHandle session, SafeWaitHandle signalEvent, String path, String query, EventLogHandle bookmark, IntPtr context, IntPtr callback, Int32 flags)
       at System.Diagnostics.Eventing.Reader.EventLogWatcher.StartSubscribing()
       at Microsoft.Office.Datacenter.ActiveMonitoring.LocalDataAccess.InitializeProbeResultNotification(DateTime startTime)
       at Microsoft.Office.Datacenter.ActiveMonitoring.LocalDataAccess.Initialize(IEnumerable`1 discoveryWorkItems)
       at Microsoft.Exchange.ActiveMonitoring.MonitoringWorker.Activate()
       at Microsoft.Exchange.ActiveMonitoring.MonitoringWorker.Run(String[] args) 
    Watson report about to be sent for process id: 11156, with parameters: E12IIS, c-RTL-AMD64, 15.00.0847.032, msexchangerepl, M.O.Datacenter.ActiveMonitoringLocal, M.O.D.A.CrimsonReader`1.ReadNext, System.UnauthorizedAccessException, e552, 15.00.0847.030.
    ErrorReportingEnabled: True 
    Cheers,
    Yannick

    Hi,
    The Exchange Health Manager Service is used to manage worker process. It's used to build, execute, and start and stop the worker process, as needed. It's also used to recover the worker process in case that process fails, to prevent the worker process from
    being a single point of failure.
    Please check whether the Exchange Health Manager Service is running well.
    Besides, please check the application log to see if there is any related events that can be used to troubleshoot this issue.
    Best regards,
    Belinda
    Belinda Ma
    TechNet Community Support

  • When I export a AAF file from Protools 9 and Import the file into Logic ProX the drum track is out of sync.  I created the drum loop using NI Maschine.  Has anyone else seem this??

    When I export an AAF file/project from Protools 9 using an external drive and import the AAF into Logice Pro X the drum track does not play correctly.  It is out of sync with the rest of the track.  I created the drum loop as a plugin using Native Instruments Maschine. Has anyone else had this problem??  Also how would I go about exporting the midi tracks from the Protools session.  The midi track does not show when the file is imported to Logic Pro X.  The midi data should export with the AAF file correct??

    Are you using any plugins in Logic?
    In Preferences/Audio  under the General tab, how do you have the plug-in-latency compensation set?

  • 1488: The workstation is no longer imported to the tree from where you are attempting to launch the operation. The Remote Management session cannot proceed.

    After upgrading a Windows XP Pro SP1 machine to the ZfDagent from the
    zfd65u2 patch I receive the following error:
    1488: The workstation is no longer imported to the tree from where you are
    attempting to launch the operation. The Remote Management session cannot
    proceed.
    For now I have went back to the ZfD 4 IR5 agent which doesn't exhibit this
    problem. Any ideas?
    Jim Webb

    Jim,
    It appears that in the past few days you have not received a response to your
    posting. That concerns us, and has triggered this automated reply.
    Has your problem been resolved? If not, you might try one of the following options:
    - Do a search of our knowledgebase at http://support.novell.com/search/kb_index.jsp
    - Check all of the other support tools and options available at
    http://support.novell.com.
    - You could also try posting your message again. Make sure it is posted in the
    correct newsgroup. (http://support.novell.com/forums)
    Be sure to read the forum FAQ about what to expect in the way of responses:
    http://support.novell.com/forums/faq_general.html
    If this is a reply to a duplicate posting, please ignore and accept our apologies
    and rest assured we will issue a stern reprimand to our posting bot.
    Good luck!
    Your Novell Product Support Forums Team
    http://support.novell.com/forums/

  • How can one powershell.exe session start up a new powershell.exe session in a new window?

    How can one powershell.exe session start up a new powershell.exe session in a new window?

    Er... good luck with that.  :)  If you know the shortcut that was used to launch the current window, you could pass that shortcut path to Start-Process, but that would only work if you did not move or resize the original window, etc.  For
    example, on my computer I can do this:
    Start-Process 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Windows PowerShell\Windows PowerShell.lnk'

  • I am using Iphoto 11 ver 9.4.3 on mac using oxs 10.8.5 i want to export calendar projects to an external hard drive. what is the easiest way to do this? i have tried export and import but it didn't seem to work.

    I am using Iphoto 11 ver 9.4.3 on mac using oxs 10.8.5 i want to export calendar projects to an external hard drive. my goal is to store them in an external hard drive so it doesn't use up memory on the mac hard drive. is it possible to copy the specific projects without copying the entire library? what is the easiest way to do this? i have tried export and import but it didn't seem to work.

    What do you not understand?
    You can duplicate the iPhoto library (command - D ) and delete everything except the project and its photos from the copy and move that
    Or
    However the calendar takes very little space - it is simpy database entries - it is the photos in the calendar that take space - and for most people you would wnat to keep those photos in your library
    you can use a photo in 50 calendars and it still is only one photo in your library - as I explained calenders do not exist as such - they are simply database entries telling iPhotop how to display the calendar - they take almost no space at all
    LN

  • I was backing up my iPhone and importing photos onto iPhoto at the same time , then suddenly it says no more space available (i had 48GB before i do this and now i have 18GB) i can't find the back up or the photo anywhere , how can i delete them ?

    i was backing up my iPhone and importing photos onto iPhoto at the same time , then suddenly it says no more space available (i had 48GB before i do this and now i have 18GB) i can't find the back up or the photo anywhere , how can i delete them ? i dont need the pictures or the back ups , i want to delete them but they are not there

    Empty the Trash if you haven't already done so. If you use iPhoto, empty its internal Trash first:
    iPhoto ▹ Empty Trash
    Do the same in other applications, such as Aperture, that have an internal Trash feature. Then reboot. That will temporarily free up some space.
    According to Apple documentation, you need at least 9 GB of available space on the startup volume (as shown in the Finder Info window) for normal operation. You also need enough space left over to allow for growth of the data. There is little or no performance advantage to having more available space than the minimum Apple recommends. Available storage space that you'll never use is wasted space.
    When Time Machine backs up a portable Mac, some of the free space will be used to make local snapshots, which are backup copies of recently deleted files. The space occupied by local snapshots is reported as available by the Finder, and should be considered as such. In the Storage display of System Information, local snapshots are shown asBackups. The snapshots are automatically deleted when they expire or when free space falls below a certain level. You ordinarily don't need to, and should not, delete local snapshots yourself. If you followed bad advice to disable local snapshots by running a shell command, you may have ended up with a lot of data in the Other category. Reboot and it should go away.
    See this support article for some simple ways to free up storage space.
    You can more effectively use a tool such as OmniDiskSweeper (ODS) to explore the volume and find out what's taking up the space. You can also delete files with it, but don't do that unless you're sure that you know what you're deleting and that all data is safely backed up. That means you have multiple backups, not just one.
    Deleting files inside an iPhoto or Aperture library will corrupt the library. Any changes to a photo library must be made from within the application that created it. The same goes for Mail files.
    Proceed further only if the problem isn't solved by the above steps.
    ODS can't see the whole filesystem when you run it just by double-clicking; it only sees files that you have permission to read. To see everything, you have to run it as root.
    Back up all data now.
    If you have more than one user account, make sure you're logged in as an administrator. The administrator account is the one that was created automatically when you first set up the computer.
    Install ODS in the Applications folder as usual. Quit it if it's running.
    Triple-click anywhere in the line of text below on this page to select it, then copy the selected text to the Clipboard by pressing the key combination command-C:
    sudo /Applications/OmniDiskSweeper.app/Contents/MacOS/OmniDiskSweeper
    Launch the built-in Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window (command-V). You'll be prompted for your login password, which won't be displayed when you type it. You may get a one-time warning to be careful. If you see a message that your username "is not in the sudoers file," then you're not logged in as an administrator.
    The application window will open, eventually showing all files in all folders, sorted by size with the largest at the top. It may take a few minutes for ODS to finish scanning.
    I don't recommend that you make a habit of doing this. Don't delete anything while running ODS as root. If something needs to be deleted, make sure you know what it is and how it got there, and then delete it by other, safer, means. When in doubt, leave it alone or ask for guidance.
    When you're done with ODS, quit it and also quit Terminal.

  • Mac OSX, 10.7.5, LR 5.6  After creating a new folder in the Destination section and importing images, the new folder name appears as 2010, no matter what name I give it.  Why is it doing this?

    Mac OSX, 10.7.5, LR 5.6  After creating a new folder in the Destination section and importing images, the new folder name appears as 2010, no matter what name I give it.  Why is it doing this?

    I am experiencing Mavericks failing to copy subdirectories from usb sticks, I am backing up game saves from a console. Both sticks I use are fine, same permissions of course since the console wrote the files. Sometimes it copies, sometimes it doesn't. It seems to be related to the mounting process.
    Thank God Apple hasn't (yet) broken bash.

  • TS1363 Ipod does not appear in my computer or recognized in itunes. When ipod is connected a window pos up aking to import photos off the device and when this is closed the ipod cannot be recognized. Any Help?

    Ipod does not appear in my computer or recognized in itunes. When ipod is connected a window pos up aking to import photos off the device and when this is closed the ipod cannot be recognized. Any Help?

    Which OS are you using? 
    In the meantime, research your problem in Knowledge Base. 

  • I have the 2nd Gen iPad and imported my photos from my computer to my iPad awhile back. Now I'd like to sync it to new MacBook Pro and my albums are not showing up? Anyone know how to fix this?

    I have the 2nd Gen iPad and imported my photos from my computer to my iPad awhile back. Now I'd like to sync it to new MacBook Pro and my albums are not showing up? Anyone know how to fix this?

    You'll have to transfer them from the pc to the mac.
    There are some options
    Importing personal photos & videos from device to  your computer
    http://support.apple.com/kb/HT4083?viewlocale=en_US&locale=en_US
    Managing photos/videos
    Iphoto app for iOS
    http://www.apple.com/support/ios/iphoto/
    photo manager pro
    https://itunes.apple.com/sg/app/photo-manager-pro/id393858562?mt=8
    Photo transfer app
    http://www.phototransferapp.com
    Dropbox
    https://www.dropbox.com/referrals/NTMzMjg0NjkzOQ?src=global9
    Picasa
    http://picasa.google.com
    photo manager pro 
    https://itunes.apple.com/sg/app/photo-manager-pro/id393858562?mt=8

  • In Pages 09 we can do Mail Merge and Import Styles from a document. Can someone please explain how we can do this with the new version of Pages 5.1. Even Apple solutions are only valid for Pages Version 09. What a DOWN GRADE!

    In Pages 09 we can do Mail Merge and Import Styles from a document. Can someone please explain how we can do this with the new version of Pages 5.1. Even Apple solutions are only valid for Pages Version 09. What a DOWN GRADE! Thank god Pages 09 is still there.

    …and the other 98 missing features.
    Just use Pages '09, which should be in your Applications/iWork folder.
    Rate/review Pages 5 in the App Store.
    Peter

Maybe you are looking for

  • What is causing my Safari to crash at least once a day?

    I can't figure it out! I tried the whole plug-in thing where you test and see, but that didn't work. What does my report say? Process: Safari [22619] Path: /Applications/Safari.app/Contents/MacOS/Safari Identifier: com.apple.Safari Version: 5.0.3 (65

  • How do i find out what the inforamtion that is stored under "other" in my ipad2 is?

    I have just backed up my ipad and i noticed that there was an massavie amount of storage used by the "other" in storage.  I was wondering if there is anyway that i can find out what it is and how can i delete some of the information to free up space

  • 10.9 Safari wont open

    I recently upgraded to Mavericks then installed the first series of updates ( imovie, keynote etc etc ) but all of a sudden when I attempt to open Safari, I get a message from Virus Barrier stating " Blocked access to info.plist ". The dock shows the

  • Competition with Business Catalyst and Sharepoint

    Do DW web developers have a future? Do business owners mistrust web developers so much that they are willing to settle for a cookie-cutter website? I find it interesting and somewhat unsettling that no matter what advances are made in technology, web

  • My code to "select" an element in the Tree UI element is not consistently working

    Hi, I created a Web Dynpro component that does many things.  One feature is do display information in a Tree UI element.  I use the TreeNodeType and recursive context node to build a nice tree representing what the customer wants.  Since this tree co