get-wmiobject gpo scripts

Welcome Forums General PowerShell Q&A get-wmiobject gpo scripts

This topic contains 4 replies, has 3 voices, and was last updated by

3 years, 2 months ago.

  • Author
  • #35159

    Topics: 5
    Replies: 18
    Points: 0
    Rank: Member

    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

    Topics: 5
    Replies: 18
    Points: 0
    Rank: Member

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

  • #35162

    Topics: 10
    Replies: 122
    Points: 2
    Rank: Member

    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

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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

    Topics: 5
    Replies: 18
    Points: 0
    Rank: Member

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

    I run this on later version and works great.

The topic ‘get-wmiobject gpo scripts’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort