header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Login Script Drive Mapping via Powershell
Last Post 31 May 2011 09:42 AM by Kingu. 7 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
KinguUser is Offline
New Member
New Member
Posts:14
Avatar

--
23 Jun 2010 09:23 AM
    Good day all.

    I'm new here, but am rapidly picking up on Powershell.  As such, I'm in the process of converting our old KixTart login script over to powershell as a test, see how it goes.  My first issue I've run into is Mapping network drives.

    It seems simple enough:

    $Mapper = New-Object -com Wscript.Network; $Mapper.mapnetworkdrive("G:","\\server\g")

    That works fine.  However, the way we determine what drives get mapped is via an .ini file we read.  Now, I've converted it over to an XML file, that looks something like this:


    [OfficeDrives]
    [Drive]"G:","\\server\g"[/Drive]
    [Drive]"H:","\\server\h"[/Drive]
    [/OfficeDrives]
    <

    So, what I'm trying next is this:

    [xml]$LogonSettings = get-content c:\powershell\logonsettings.xml
    $Mapper = New-Object -com Wscript.Network;
    $LogonSettings | select-xml -xpath "//OfficeDrives/Drive" | Foreach $Mapper.mapnetworkdrive($_node.InnerXML)

    That doesn't work.  I get this:

    Cannot find an overload for "MapNetworkDrive" and the argument count: "1". At C:\powershell\GetDrives.ps1:10 char:90 + $LogonSettings | select-xml -xpath "//OfficeDrives/Drive" | Foreach $Mapper.mapnetworkdrive <<<< ($_node.InnerXML) + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest

    I'm trying to decypher why this doesn't work.. I suspect I'm doing something silly to miss this.  Perhaps it's my Foreach?  It won't let me do what I'm trying? 

    I thought I COULD stick each drive letter mapping into it's own variable and then map the drives, and that works.. but it seems clunky.. like there has to be a more elegant way of doing this in powershell?

    Help?


    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    23 Jun 2010 09:44 AM
    $_.node.InnerXML
    You'd left out the . after $_


    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    KinguUser is Offline
    New Member
    New Member
    Posts:14
    Avatar

    --
    23 Jun 2010 10:14 AM
    Well, trying that, I don't seem to see any more useful information, as a newbie, unfortunately. I see a lot of:

    Stopped at: etc.. etc.. messages as I step into the line that I suspect is my issue (where my foreach is).


    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    23 Jun 2010 10:42 AM
    could you upload an example xml file?  values do not have to be accurate, but the format is what's important.


    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    KinguUser is Offline
    New Member
    New Member
    Posts:14
    Avatar

    --
    23 Jun 2010 10:43 AM
    Attached.

    And just to make sure I'm clear, I did add the period in $_.node.InnerXML, same thing.

    001_test.xml

    KinguUser is Offline
    New Member
    New Member
    Posts:14
    Avatar

    --
    28 Jun 2010 03:41 PM
    This is resolved. Needless to say it was a combo of issues from the formatting of the XML, Which Iv'e subsequently changed, to the code. The core of the code is as follows...

    [xml]$LogonSettings = get-content c:\powershell\logonsettings.xml

    $Mapper = New-Object -com Wscript.Network;

    $LogonSettings.RenoDrives.Drive | %{ $Mapper.MapNetworkDrive($_.DriveLetter, $_.DriveUNC) }


    And it works perfectly! Hopefully this'll help someone down the road, though I doubt it :)


    superfishnzUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    29 May 2011 02:22 AM
    I've tried converting my company's KIX login script to Powershell as well. Spent a full THREE days doing so. To be honest with you, the Powershell script was a lot more long winded and KIX was a lot easier to read, esp for another Sys Admin person who has never really worked with scripting codes, Kix is easier to read from the offset.

    I wrote about my findings and also documented what I did with my Powershell and Kix login scripts here: http://thisishelpful.com/powershell...tings.html

    Hope this is of help to others.

    Thanks,
    Binh


    KinguUser is Offline
    New Member
    New Member
    Posts:14
    Avatar

    --
    31 May 2011 09:42 AM
    Thanks!  I've actually finished migrating things over to Powershell.  It definately is longer winded, but /SOOOO/ much faster.  In fact, my script runs on average of just under 2 seconds from start to finish.  Kix was averaging a little over 20 seconds, so the speed is all worth it to the end users.


    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer