0

We are performing an audit of different networks and need to distinguish between domains. The code I currently use will export to .csv but just uses the title I choose. What I need is for it to automatically name the .csv file with the domain name in it.

Below is my current code:

Import-Module ActiveDirectory
Get-ADObject -filter 'objectclass -eq "user"' -properties CN,DisplayName,Discription | select | export-csv -NoTypeInformation "c:\ADUsers.csv"
1
  • 1
    did you do some research on your own? this shouldnt be too hard to figure out... you can get the domain name with (gwmi win32_computersystem).domain just put it in a variable and use it in your export-csv statement Commented Nov 4, 2014 at 19:01

1 Answer 1

1

Did you want just the current domain, or the domain with parent domains included?

Current Domain Name:

Import-Module ActiveDirectory
$name = Get-ADDomain | Select -ExpandProperty NetBIOSName
Get-ADObject -Filter 'objectclass -eq "user"' -Properties CN,DisplayName,Discription | select |  
Export-Csv -NoTypeInformation "c:\" + $name + ".csv"
Sign up to request clarification or add additional context in comments.

1 Comment

One small oversight: the Import-Module statement needs to come before the Get-ADDomain statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.