Home > Back-end >  Extract Powershell also Domain Only Folder LocalUserAccount
Extract Powershell also Domain Only Folder LocalUserAccount

Time:03-19

Bonjour je souhaiterais récupérer uniquement le domaine d'un propriétaire d'un dossier "Domain"\User malheureusement la commande Get-WmiObject Win32_UserAccount ne m'affiche rien je souhaiterais juste ressortir le domaine merci de votre aide.

$Path = "C:\Gabriel" $LogPath = "C:\Gabriel" Get-ChildItem $Path | Select Name,Directory,

                  @{Name="Owner";Expression={(Get-ACL $_.Fullname).Owner}},

                  @{Name='Domain';Expression={(Get-WmiObject Win32_UserAccount).Domain}} | 

Export-Csv $LogPath\FileFolderOwner.csv -NoTypeInformation

gabriel

CodePudding user response:

Translation was:

I would like to retrieve only the domain of a folder owner

So you can split the domain from DOMAIN\username:

$Path = "C:\temp" 
Get-ChildItem $Path | Select Name,Directory,
    @{Name="Owner";Expression={(Get-Acl $_.Fullname).Owner}},
    @{Name='Domain';Expression={((Get-Acl $_.Fullname).Owner -split '\\')[0]}}

# output

Name     Directory Owner         Domain 
----     --------- -----         ------ 
folder1            MYDOMAIN\user MYDOMAIN
folder2            MYDOMAIN\user MYDOMAIN
file.txt c:\temp   MYDOMAIN\user MYDOMAIN

You didn't get anything because Get-WmiObject Win32_UserAccount does not have a filter like:

# Do not use this. It is too slow
@{Name='Domain';Expression={
  (Get-WmiObject Win32_UserAccount -filter "Name='Example'").Domain
}}
  • Related