none
Select Username, Regex RRS feed

  • Question

  • Working on getting the username out of the Get-childItem directory path, and im having trouble getting a regex to strip out the path from the directory and only outputting the username. 

    I know the code is quite dirty at the moment, but once I can get the regex, I'll go back and do some cleanup. 

    User = $stuff.Directoryname is where I would like to place new code. 

    Thanks. 

    $ComputerName = 'PC'
    
    # Get users
    $users = Get-ChildItem -Path "\\$ComputerName\C$\Users"
    
    # Loop through users and delete the file
    $users | ForEach-Object {
       $stuff = gci -Path "\\$ComputerName\C$\Users\$($_.Name)\AppData\Roaming\*\*\*\*\*\AdobeConnectaddin.exe"
       
       [PSCustomObject]@{
         Found = $stuff.Name
         Version = $stuff.VersionInfo.FileVersion
         User = $stuff.DirectoryName
       }
    }

    Might help to add that the current output looks like this, from the DirectoryName property: 

    \\PC\C$\Users\SomeUser\AppData\Roaming\Macromedia\Flash Player\www.macromedia.com\bin\adobeconnectaddin


    • Edited by prisoner107 Thursday, September 7, 2017 1:30 PM
    Thursday, September 7, 2017 1:05 PM

Answers

  • Is this what you are asking?


    PS C:\> ('\\PC\C$\Users\SomeUser\AppData\Roaming\Macromedia\Flash Player\www.macromedia.com\bin\adobeconnectaddin' -split '\\')[5]
    SomeUser
    


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by prisoner107 Thursday, September 7, 2017 2:24 PM
    Thursday, September 7, 2017 2:10 PM
    Moderator

All replies

  • Is this what you are asking?


    PS C:\> ('\\PC\C$\Users\SomeUser\AppData\Roaming\Macromedia\Flash Player\www.macromedia.com\bin\adobeconnectaddin' -split '\\')[5]
    SomeUser
    


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by prisoner107 Thursday, September 7, 2017 2:24 PM
    Thursday, September 7, 2017 2:10 PM
    Moderator
  • Excellent, I can make this work. Thanks!!
    Thursday, September 7, 2017 2:24 PM