Deployment Solution

 View Only
  • 1.  Losing drive mappings

    Posted Feb 20, 2012 03:43 PM

     

    I have created a script that maps a drive based on the user's IP address; in this case the drive letter is "V". The script is written in PowerShell, and outside of the AtirisDS console works great. In powershell I am using “NET USE” to map the drive, not New-PSDrive.
     
    If I make a job that has two task, the first task is mapping the drive with the script, and the second one calling that mapping, it errors. But if call that mapped drive while still in the tasked that it was mapped, it is there, just vanishes when the next task start. 
     
    I am appreciative of any help you can offer.
     
    c:
     
    #Store IPV4 address as string
    $ipaddress = ipconfig | findstr "IPv4"
    $ipaddress = $ipaddress[0].tostring()
    if ($ipaddress -eq " ") { $ipaddress = ipconfig | findstr "IPv4" }
    $ipaddress = $ipaddress.tostring().replace("IPv4 Address. . . . . . . . . . . : ", "")
     
    #Determine which application server to map
    if ($ipaddress.StartsWith( "   xxx.x.xx." )) { $AppServer = "FILE-SERVER1" }
    elseif ($ipaddress.StartsWith( "   xxx.xx.xxx." )) { $AppServer = "FILE-SERVER2"}
    else { $AppServer = "FILE-SERVER3" } #All others
     
    #Set the drive and path information
    $Drive = "V:"
    $UNC = "\\" + $AppServer + "\Apps"
     
    #Disconnect drive if mapping already exists
    if ( Test-Path -path "V:\" ) { net use /delete v: /y }
     
    #Map the drive
    net use v: $UNC /PERSISTENT:YES /USER:DOMAIN\USER "password"


  • 2.  RE: Losing drive mappings

    Posted Feb 20, 2012 03:49 PM

    Sorry I should of included this in my last post, I am on DS 6.9 SP4



  • 3.  RE: Losing drive mappings

    Posted Feb 20, 2012 05:45 PM

    I'm not a PowerShell wizard, but does it behave differently if you remove the if statement that checks for it and deletes?  I mean, if this were a BAT, you would map the drive and then exit since you're done.  Can you force that in PowerShell?



  • 4.  RE: Losing drive mappings

    Posted Feb 21, 2012 09:16 AM

    If you run net use to map a drive, to a used drive letter then it will fail. The "if mapped" statement is before the the the map statement. So the order of things are, "if v is mapped, remove it", then map v:. Also like i said before, after powershell has ran, but still in the same task, the mapped drive is a variable, but in the next task it is not.



  • 5.  RE: Losing drive mappings

    Posted Feb 22, 2012 09:43 AM

    Just to give a clearer picture, here is the report from "net use" ran after the powershell script, but in the same task:

     

    Status       Local     Remote                    Network
     
    -------------------------------------------------------------------------------
    OK           V:        \\HOU-TECHSVS01\Applications 
                                                    Microsoft Windows Network
    The command completed successfully.
     
    Below is the report from the next task in the sequence:
     
    Status       Local     Remote                    Network
     
    -------------------------------------------------------------------------------
    Unavailable  V:        \\HOU-TECHSVS01\Applications 
                                                    Microsoft Windows Network
    The command completed successfully.

     



  • 6.  RE: Losing drive mappings

    Posted Feb 24, 2012 11:40 AM

    So today I try to map the drive with vbscript using the the wsrcipt.network object, and it worked fine with no issues... Don't know if it helps but I am doing all of this on a Windows 7 machine.

     

    Option Explicit
    On Error Resume Next
     
    Dim strComputer, strServer
    Dim objWMI, objIPConfig, objNetwork
    Dim colIPConfig
    Dim i
     
    strComputer = "."
    Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set objIPConfig = objWMI.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
     
    For Each colIPConfig In objIPConfig
    If Not IsNull(colIPConfig.IPAddress) Then 
    For i=LBound(colIPConfig.IPAddress) To UBound(colIPConfig.IPAddress)
    If Not IsNull(colIPConfig.IPAddress(i)) And colIPConfig.IPAddress(i) <> "0.0.0.0" Then
    If InStr(colIPConfig.IPAddress(0), "xxx.x.xx.") Then 
    strserver = "FILE-SERVER01"
    ElseIf InStr(colIPConfig.IPAddress(0), "xxx.xx.xxx.") Then 
    strserver = "FILE-SERVER02"
    Else
    strserver = "FILE-SERVER03"
    End If
    End If
    Next
    End If
    Next
     
    Set objNetwork = CreateObject("WScript.Network") 
    objNetwork.MapNetworkDrive "V:", "\\" + strServer + "\Applications",,"DOMAIN\USER", "password"
     
    But when I call the same object from powershell I get the same resualts from before... NET USE showing that the drive is unavailable.
    c:
     
    #Store IPV4 address as string
    $ipaddress = ipconfig | findstr "IPv4"
    $ipaddress = $ipaddress[0].tostring()
    if ($ipaddress -eq " ") { $ipaddress = ipconfig | findstr "IPv4" }
    $ipaddress = $ipaddress.tostring().replace("IPv4 Address. . . . . . . . . . . : ", "")
     
    #Determine which application server to map
    if ($ipaddress.StartsWith( "   xxx.x.xx." )) { $AppServer = "FILE-SERVER1" }
    elseif ($ipaddress.StartsWith( "   xxx.xx.xxx." )) { $AppServer = "FILE-SERVER2"}
    else { $AppServer = "FILE-SERVER3" } #All others
     
    #Set the drive and path information
    $Drive = "V:"
    $UNC = "\\" + $AppServer + "\Apps"
     
    #Disconnect drive if mapping already exists
    if ( Test-Path -path "V:\" ) { net use /delete v: /y }
     
    #Map the drive
    (new-object -com WScript.Network).MapNetworkDrive("v:",$UNC,, "swn\altirisro", "You can only read!")