PowerShell Script to get AD user properties particular search Base OU

Amit Hanamannavar 1 Reputation point
2020-06-30T11:57:42.583+00:00

Import-Module activedirectory
Get-ADUser -Filter * -SearchBase "" -Properties * | Select-Object DisplayName,samaccountName,EmailAddress,Enabled,Created,canonicalname,LastLogondate,memberof | ConvertTo-Csv | Out-File C:\Temp\tmp.csv
Import-Csv "C:\Temp\tmp.csv" | Export-Csv -Delimiter "," "C:\Temp\UserData.csv" -NoTypeInformation
Remove-Item -Path C:\Temp\tmp.csv

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,500 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Shashi Shailaj 7,581 Reputation points Microsoft Employee
    2020-06-30T13:01:24.607+00:00

    @Amit Hanamannavar ,

    Thank you for sharing your knowledge. This script looks good. It does not seem that you have any query around this. I would suggest you to contribute directly using nuget API to the powershellgallery.com so that its accessible from any machine for anyone who points to PSGallery repository on their windows machine.

    Please logon to the https://www.powershellgallery.com/ and signin/register if you do not have an account . you can use your Microsoft account to signin (similar as the one you use this QnA forum.) You can then go to the Apikeys section on your profile https://www.powershellgallery.com/account/apikeys to create an APi key as per your need to publish the package.

    11032-psapi01.jpg

    After this you can publish the same to the Powershell Gallery using the Publish-module/Publish-Script cmdlet as per the module/script you would like to publish. using NugetAPIkey you had obtained in the last step

    Publish-Script -Path <scriptPath> -NuGetApiKey <apiKey>  
    

    11092-psapi02.jpg

    Please check more in the documentation on how to create and publish an item along with the best practices about publishing to powershell gallery. Hope this is useful for future scripts. you will also be able to access them on any machine with powershell connected to the web. hope this helps . If I have misunderstood your query , please do let us know about the question you have around the script and we will be happy to assist you or point to the right resources.

    Thank you.

    0 comments No comments