Reputation: 3
i created a .ps1 script to monitor our clients and it works like a charm. Unfortunatly you always see a powershell window popping up when executing it so I wrapped it into a .vbs script that executes with wscript and use scheduled tasks from GPO to run daily. Both the ps1 file and the vbs file work when I manually execute the scripts but I can't get it to work in the GPO. Everything behaves as it should except mapped drives.
code snipped that works when i run the .ps1 file:
$Network_Drive=(Get-SMBMapping | Select-Object -expand RemotePath) -join "`r`n,"
$Network_Drive | Out-File \\a\b\c.csv
also works:
$Network_Drive= (Get-CimInstance -Class Win32_NetworkConnection | Select -ExpandProperty RemoteName) -join "`r`n,"
vbs script:
command = "powershell.exe -nologo -ExecutionPolicy Unrestricted -File \\network\link\to\the\script.ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command,0
Expected result:
,\\mapped\drive1\
,\\mapped\drive2\
Result:
,
,
I'm not sure if it's a permission thing with the group policy or if I should use a different method. Everything works as expected when I don't use the .vbs but the ps1 file directly. Network Printer show up as expected.
Upvotes: 0
Views: 84
Reputation: 3
I solved my question by putting the scripts on the client and not on a shared drive.
Upvotes: 0
Reputation: 24565
The first question is: Why do you need a VBScript WSH script?
If the goal is to get a list of mapped drives from a VBScript script, there's no need to shell PowerShell and perform output parsing. Instead, just use the WshNetwork
object directly in your WSH script. Example:
Dim WshNetwork
Set WshNetwork = CreateObject("WScript.Network")
Dim Output
Output = ""
Dim Drives, I
Set Drives = WshNetwork.EnumNetworkDrives()
For I = 0 To Drives.Count - 1 Step 2
If Output = "" Then
Output = Drives.Item(I) & " => " & Drives.Item(I + 1)
Else
Output = Output & vbNewLine & Drives.Item(I) & " => " & Drives.Item(I + 1)
End If
Next
WScript.Echo Output
But again: Why do you need a WSH VBScript script?
Upvotes: 0