This is a simple DFS structure. First line is DFS Namespace Server (1), second (2) is the share responsible
I have now the following task.
1) I need to extract from that that script output only the lines starting with "\\RUM\DATA\AAA\DEPT\Finance" and their apropriate shares. So in my case the out put would be something like:
Remarks:
the output from the script can be much much longer. But the order is always the same.DFS Namespace Server (1), second (2) is the share responsible
Hope I'm not too late. Here is a script which will do what I think you're after. You just need to specify your server which has the DFS store and which share you want to look for:
' ============================================ User Changable Items
strComputer = "RUM" ' String for computer with DFS Shares
strSearch = "\\RUM\DATA\AAA\DEPT\Finance\Holland" ' String for Share
Let me know if you need any more help with this.
Option Explicit On Error Resume Next Dim intCount, intLoop Dim strComputer, strShareName, strSearch Dim objWMIService, objDFSTarget, objShare Dim colDFSTargets, colDrives, colShares Dim aryShares() ReDim aryShares(1,0) intCount = 0' ============================================ User Changable Items strComputer = "RUM" ' String for computer with DFS Shares strSearch = "\\RUM\DATA\AAA\DEPT\Finance\Holland" ' String for Share' ============================================= Populate Array With Share Details Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDfsTargets = objWMIService.ExecQuery ("Select * from Win32_DFSTarget") For each objDfsTarget in colDfsTargets ReDim Preserve aryShares(1, intCount) aryShares(0,intCount) = objDfsTarget.LinkName aryShares(1, intCount) = chr(92)&chr(92)& objDfsTarget.ServerName & chr(92)& objDfsTarget.ShareName intCount = intCount + 1 Next' ============================================ Cycle Through Shares Array For intLoop = 0 to uBound(aryShares,2)' ============================================ Matches Shares with Search String If uCase(aryShares(1,intLoop)) = uCase(strSearch) Then strComputer = mid(aryShares(1,intLoop),3,Int(InStr(3,aryShares(1,intLoop),"\",1)-3)) strShareName = mid(aryShares(1,intLoop),len(strComputer) + 4,Int(InStr(3,aryShares(1,intLoop),"\",1))) wscript.echo "Server: " & strComputer' ============================================ Gets local path for Share Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colShares = objWMIService.ExecQuery("Select * from Win32_Share Where Name = '" & strShareName & "'") For each objShare in colShares Wscript.Echo "Path: " & vbTab & objShare.Path Next wscript.echo vbcrlf End IF Next
You don't need the array if you want the script to be smaller. It started off on another path and didn't think about not using it until now.
Zorge
ASKER
Hi Enigma,
thank you for your quick reply.
On the script provided by you I get this as response:
***********************************************************************************
C:\install>cscript all_1.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
with the ONE line below that search string. Which is then stripped to (has to be stripped since we are first looking for who is namespace server for the above mentioned folder)
\\DFS-1\TELEKOM
\\DFS-3\TELEKOM
then both lines are resolved to local pathes like:
which I will later use for operation like
(DFS-1 becomes VARIABLE1 ; C:\Zimbabwe\TELEKOM VARIABLE2, I will process it line after line untill I'm finished with all servers)
For those playing at home here is the script again but tweaked. Remember kids always program on a good nights sleep.
Option Explicit On Error Resume Next Dim strComputer, strSearch, strVariable1, strVariable2 Dim intAryLoop Dim objWMIService, objDFSTarget, objShare Dim colDFSTargets, colDrives, colShares Dim aryMatches() ReDim Preserve aryMatches(1,0) ' ============================================ User Changable Items strComputer = "RUM" ' String for computer with DFS Shares strSearch = "\\RUM\DATA\AAA\DEPT\Finance\Holland" ' String for Share' ============================================ Get List Of DFS Shares On Target Computer Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDfsTargets = objWMIService.ExecQuery ("Select * from Win32_DFSTarget") ' ============================================ Matches Shares with Search String For each objDfsTarget in colDfsTargets If uCase(objDfsTarget.LinkName) = uCase(strSearch) Then' ============================================ Gets local path for Share Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & objDfsTarget.ServerName & "\root\cimv2") Set colShares = objWMIService.ExecQuery("Select * from Win32_Share Where Name = '" & objDfsTarget.ShareName & "'") For each objShare in colShares strVariable2 = objShare.Path Next strVariable1 = objDfsTarget.ServerName End IF' ============================================ Store Information In Match Array IF strVariable1 <> "" or strVariable2 <> "" THEN IF aryMatches(0,uBound(aryMatches,2)) = "" THEN aryMatches(0,0) = strVariable1 aryMatches(1,0) = strVariable2 Else ReDim Preserve aryMatches(1,uBound(AryMatches,2) + 1) aryMatches(0,uBound(aryMatches,2)) = strVariable1 aryMatches(1,uBound(aryMatches,2)) = strVariable2 End If End IF Next' ============================================ Display Results In Match Array wscript.echo "Results:" For intAryLoop = 0 to uBound(aryMatches,2) wscript.echo aryMatches(0,intAryLoop) & " " & aryMatches(1, intAryLoop) Next
Hope I'm not too late. Here is a script which will do what I think you're after. You just need to specify your server which has the DFS store and which share you want to look for:
' ==========================
strComputer = "RUM" ' String for computer with DFS Shares
strSearch = "\\RUM\DATA\AAA\DEPT\Finan
Let me know if you need any more help with this.
Open in new window