get-wmiobject gpo scripts

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Ian Fermer Ian Fermer 7 months, 2 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #35159
    Profile photo of Ian Fermer
    Ian Fermer
    Participant

    Hi All,

    So I'm trying to get a 3.0 script working in powershell 2.0, I cannot upgrade powershell so I'm a bit stuck.

    $user = [Environment]::UserName
    $path = "\\server\scripts$\$user.csv"

    start-sleep -s 20
    Get-WmiObject Win32_MappedLogicalDisk | Export-Csv $path -NoTypeInformation

    As append does not work I'm getting it to create a csv for each user.
    However even though the script works with the user logged in. When running it via GPO in the login or log off script, the output is a empty file.

    I made the script sleep so the drives get created however it creates just a empty file.

    Instead of running it I have also called the script from command prompt but still a empty file. Anyone know what I'm missing?

    #35160
    Profile photo of Ian Fermer
    Ian Fermer
    Participant

    I should add, I can run get-childitem instead of my get-wmiobject and I get results

    #35162
    Profile photo of Mark Hammonds
    Mark Hammonds
    Participant

    do you want just the Paths or all the information

    This will get you just the paths

    $Paths = Get-WmiObject Win32_MappedLogicalDisk  -ComputerName $env:COMPUTERNAME | Select ProviderName
    

    you may have to do a foreach into a custom PSObject before you export to the cvs I only have one mapped drive so I cant test

    this is all the info that provider will show

    __GENUS                      : 2
    __CLASS                      : Win32_MappedLogicalDisk
    __SUPERCLASS                 : CIM_LogicalDisk
    __DYNASTY                    : CIM_ManagedSystemElement
    __RELPATH                    : Win32_MappedLogicalDisk.DeviceID="F:",SessionID="768354"
    __PROPERTY_COUNT             : 38
    __DERIVATION                 : {CIM_LogicalDisk, CIM_StorageExtent, CIM_LogicalDevice, CIM_LogicalElement...}
    __SERVER                     : someserver
    __NAMESPACE                  : root\cimv2
    __PATH                       : \\somecomputer\root\cimv2:Win32_MappedLogicalDisk.DeviceID="F:",SessionID="768354"
    Access                       : 
    Availability                 : 
    BlockSize                    : 
    Caption                      : F:
    Compressed                   : False
    ConfigManagerErrorCode       : 
    ConfigManagerUserConfig      : 
    CreationClassName            : 
    Description                  : 
    DeviceID                     : F:
    ErrorCleared                 : 
    ErrorDescription             : 
    ErrorMethodology             : 
    FileSystem                   : NTFS
    FreeSpace                    : 142401746501632
    InstallDate                  : 
    LastErrorCode                : 
    MaximumComponentLength       : 255
    Name                         : F:
    NumberOfBlocks               : 
    PNPDeviceID                  : 
    PowerManagementCapabilities  : 
    PowerManagementSupported     : 
    ProviderName                 : \\somepath\\home$
    Purpose                      : 
    QuotasDisabled               : 
    QuotasIncomplete             : 
    QuotasRebuilding             : 
    SessionID                    : 768354
    Size                         : 199845549205504
    Status                       : 
    StatusInfo                   : 
    SupportsDiskQuotas           : False
    SupportsFileBasedCompression : False
    SystemCreationClassName      : Win32_ComputerSystem
    SystemName                   : somesystem
    VolumeName                   : fldrrdr$
    VolumeSerialNumber           : 009A9A03
    PSComputerName               : somecomputer
    
    #35165
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Keep in mind that the script may be running – and the sleep won't help this – before drives are mapped. That's especially true if the script is a startup, since the computer account doesn't have mapped drives.

    #35172
    Profile photo of Ian Fermer
    Ian Fermer
    Participant

    Even if I run at log off it does the same.

    I run this on later version and works great.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.