(For more about Ed and the group, read my previous post.) Some of my discussion with Ed led to Scripting Guy articles about Active Directory and Export-CSV. I have been truly fortunate to be a member of a PowerShell user group with him as a member and regular speaker. I had some help with direction by the Scripting Guy himself, Ed Wilson. And, of course, the best way to learn a new programming language is to have a real project instead of just exercises. As far as I can tell from my internet search, no one has written such a PowerShell function. My goals were to write something that I could use every day which would take the output of Get-ADUser, Get-ADComputer and other Get-AD* cmdlets within the ActiveDirectory module and convert the data to strings which would properly output to Export-CSV. And, although some of the data looked okay when output to the screen, values stored other than a simple string often gave me results like “”.īecause of these issues, I set out to create my first PowerShell function. There is no automatic way of handling the different date strings in Active Directory. Unfortunately, I found that getting the data I wanted was not as easy as I expected. I was excited that my long vbscripts to export data from Active Directory would be now one liners which I could send to a CSV file with the Export-CSV cmdlet. You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.If you have been following my blog, you know that I am an experienced vbscripter, but am relatively new to PowerShell. Use the Get-AdUser cmdlet in the PowerShell to get active directory users and Properties * to retrieve an additional set of users properties like HomeDirectory, HomeDrive, and ProfilePath. I hope the above article about how to get aduser home directory folder path in PowerShell is useful to you. The output of the above script to get aduser home directory size is: Count : 2 The Get-ChildItem searches for the aduser home directory recursively and uses Measure-Object to get the home directory size of the aduser account. In the above PowerShell script, Get-Aduser gets the active directory user home directory and stores it in the $aduseraccount variable. $directorysize = Get-ChildItem $Directory -recurse | Measure-Object -property length -sum $aduseraccount = Get-Aduser -Identity Arons -Properties HomeDirectory Use the Get-ChildItem cmdlet in PowerShell to get the home directory size. Using the Get-AdUser cmdlet, you can get aduser home directory. SamAccountName HomeDirectory HomeDrive ProfilePath The output of the above script returns the users having a home directory blank. In the above PowerShell script, using the Get-AdUser Filter parameter to apply filter condition to get aduser home directory like blank or an empty. Get-AdUser -Filter -SearchBase $OUPath -Properties * | Select SamAccountName,HomeDirectory,HomeDrive,ProfilePath Using the Get-AdUser Filter parameter, we can find all the ad users in the specific organizational unit having the home directory as blank. It uses the Export-CSV cmdlet in PowerShell to export a list of aduser home directory folder paths in the CSV file. Get-AdUser -Filter * -SearchBase $OUPath -Properties * | Select SamAccountName,HomeDirectory,HomeDrive,ProfilePath | Export-CSV -Path C:\PowerShell\adusers-home-directory.csv -NoTypeInformation You can export the list of ad user home directory, profile path, and home drive to CSV file using the following command. You can use Set-AdUser to set ad user home directory using PowerShell. In the above script output, a few aduser has home directory blank and other properties like home drive and profile path are blank as well.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |