Author Posts

April 17, 2017 at 8:38 am

I am trying to run a logon script to capture the logged on user network drive map file system. I run the command locally on computer and it works fine. I get the computername and file system of network drive.

if i run it as a login script I get the computer name but never the file system. I have even tried to put a start-sleep for 2 minutes. I still do not get it.

I am not sure what i am doing wrong

     $system= Get-WmiObject Win32_ComputerSystem -ComputerName localhost| Select-Object Name 
     $localdisk=Get-WMIObject Win32_Logicaldisk -filter "deviceid='M:'"  -ComputerName localhost


     $Object = New-Object PSObject -Property @{
ComputerName           = $system.Name
'M drive'              = $localdisk.FileSystem
}



$Object | Export-Csv -NoTypeInformation  \\networkdrivelocation\"$env:computername".csv

April 17, 2017 at 5:16 pm

You may be able to fix this with a pretty simple change. Right now you're using the Win32_LogicalDisk class for Get-WMIObject, where you may need to be using the Win32_MappedLogicalDisk class. I would change your code to look like the following and it should work at that point

     $system= Get-WmiObject Win32_ComputerSystem -ComputerName localhost| Select-Object Name 
     $localdisk=Get-WMIObject Win32_MappedLogicaldisk -filter "deviceid='M:'"  -ComputerName localhost


     $Object = New-Object PSObject -Property @{
ComputerName           = $system.Name
'M drive'              = $localdisk.FileSystem
}



$Object | Export-Csv -NoTypeInformation  \\networkdrivelocation\"$env:computername".csv

April 19, 2017 at 2:55 am

Bryce,

That did not work. I am beginning to think it is because of UAC on other computer.