简体   繁体   English

在Powershell中以标题中的域名导出CSV

[英]Export CSV in powershell with Domain name in title

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. 我当前使用的代码将导出到.csv,但仅使用我选择的标题。 What I need is for it to automatically name the .csv file with the domain name in it. 我需要的是它自动使用域名将.csv文件命名。

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"

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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM