POWERSHELL - map and umap network folders with diferent credentials

Posted on 2012-08-29
Last Modified: 2012-08-29

I am trying to map and unmap x$ to a network server.

That server does not belong the domain so I have to use credential.

I have been looking for information on internet but I am confused, there is methods wth vbs, etc. I am looking for the way to specifically connect by usign powershell and disconnect the share one we finish our work.

Might anyone help me?
Question by:projectja
    LVL 9

    Expert Comment

    $net = new-object -ComObject WScript.Network
    $net.MapNetworkDrive("r:", "\\romeobox\files", $false, "domain\user", "password")
    LVL 13

    Expert Comment

    Hmm ... there's already a command for that. Just open a command window and enter try
    NET USE /?

    Open in new window

    for command help. Should be usable in Powershell.

    Author Comment


    Thank you very much.

    But how could I disconnect it once I finish the task?

    Author Comment

    I prefer not to use NET USE , I would to focus on powershell specifically.

    Please, TazDevil1674, how could I discconect the mapped unit ?

    LVL 9

    Accepted Solution


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now