简体   繁体   English

Powershell导出包含活动目录安全组数据的csv文件

[英]Powershell exports csv file containing active directory security group data

I have a bat file that starts up a PS1 script, the PS1 script is supposed to go to AD and export the names listed in a Security Group. 我有一个启动PS1脚本的bat文件,该PS1脚本应该进入AD并导出安全组中列出的名称。 It runs fine and exports fine, however the data is incorrect, almost as if it is exporting some unknown data that I'm not sure where from. 它可以正常运行并可以正常导出,但是数据不正确,几乎就像是在导出一些我不确定从何处来的未知数据。 Here is my powershell script: 这是我的powershell脚本:

$uni = Read-host 'Your username'

$SG = Read-host 'Security Group'

start-sleep -s 3

powershell.exe get-adgroupmember "$SG" | export-csv -path "C:\users\$uni\desktop\members.csv"

When opening the CSV, it shows similar: 打开CSV时,显示类似:

TYPE System.String TYPE System.String

Length 79 79 63 17 34 79 26 54 1 长度79 79 63 17 34 79 26 54 1

Am I needing to declare or import a pssession? 我需要声明或导入pssession吗? if so, what is the configurationname for active directory? 如果是,活动目录的配置名称是什么?

Most likely you're getting a collection of objects in your data. 您很可能会在数据中获取对象集合。 You have to expand or join the data before passing to Export-CSV 您必须先扩展或合并数据,然后再传递到Export-CSV

See the following articles for some idea: 请参阅以下文章以了解一些想法:

1) http://blog.millersystems.com/powershell-exporting-multi-valued-attributes-via-export-csv-cmdlet/ 2) http://www.msexchange.org/kbase/ExchangeServerTips/ExchangeServer2010/Powershell/WhydoIgetSystem.StringwhenusingGet-MessageTrackingLogandexportingtoaCSV.html 1) http://blog.millersystems.com/powershell-exporting-multi-valued-attributes-via-export-csv-cmdlet/ 2) http://www.msexchange.org/kbase/ExchangeServerTips/ExchangeServer2010/Powershell/为什么在使用Get-MessageTrackingLog并导出到CSV.html时使用IgetSystem.String

The articles give the following examples: 文章给出了以下示例:

1) change the following 1)更改以下

Get-TransportServer | Get-MessageTrackingLog -ResultSize -Start "11/28/2011" -Sender nuno@letsexchange.com | Select * | Export-Csv D:\Reports\Sent_Nuno.csv -NoType

to

Get-TransportServer | Get-MessageTrackingLog -ResultSize -Start "11/28/2011" -Sender nuno@letsexchange.com | Select {$_.Recipients}, {$_.RecipientStatus}, * | Export-Csv D:\Reports\Sent_Nuno.csv -NoType

2) change the following 2)更改以下

Get-QADUser seth -IncludeAllProperties | select name, proxyaddresses | Export-Csv .seth-nojoin.csv - See more at: http://blog.millersystems.com/powershell-exporting-multi-valued-attributes-via-export-csv-cmdlet/#sthash.JCccKLui.dpuf

to

Get-QADUser seth -IncludeAllProperties | select name, @{Name=’proxyAddresses';Expression={[string]::join(“;”, ($_.proxyAddresses))}} | Export-Csv .seth-all_proxyaddresses.csv - See more at: http://blog.millersystems.com/powershell-exporting-multi-valued-attributes-via-export-csv-cmdlet/#sthash.JCccKLui.dpuf

You'll need to import the ActiveDirectory module for the get-ADGroupMember cmdlet, but I assume you've already gotten past that part as you have output instead of errors. 您需要为get-ADGroupMember cmdlet导入ActiveDirectory模块,但是我认为您已经通过了该部分,因为它具有输出而不是错误。 I don't have the ability to test currently as I can't import the module (need RSAT or AD Management Gateway Service installed), but I think you would need to insert a select command in your pipeline (to enumerate the problematic data fields) that looks something like this: 我目前无法测试,因为我无法导入模块(需要安装RSAT或AD Management Gateway服务),但是我认为您需要在管道中插入select命令(以枚举有问题的数据字段) ),看起来像这样:

powershell.exe get-adgroupmember "$SG" | Select {$_.nameOfVariableReturningSystemString}, * | export-csv -path "C:\users\$uni\desktop\members.csv

Alexander Obersht answered my question through comments, although duct_tape_coder you are also correct. 亚历山大·奥伯斯特(Alexander Obersht)通过评论回答了我的问题,尽管pipe_tape_coder也很正确。 Thanks for the help guys, appreciated. 感谢您的帮助,感激不尽。

暂无
暂无

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

相关问题 Powershell-将计算机添加到Active Directory中的安全组 - Powershell - Adding computers to a security group in Active Directory 导入CSV的Powershell脚本,将信息与Active Directory比较,按OU排序,然后将信息导出到csv - Powershell script that imports a CSV, compares the info to Active Directory, sorts it by OU, then exports the Info to csv PowerShell导入CSV以添加Active Directory安全组 - PowerShell Import CSV to add Active Directory Security Groups 如何在 PowerShell 中从 csv 查找 Active Directory 组名称? - How to look for Active Directory group name from csv in PowerShell? PowerShell:如何将 1 个用户添加到多个 Active Directory 安全组 - 具有写入权限的安全组的安全选项卡 - PowerShell: How to add 1 user to multiple Active Directory Security Groups - Security tab of the security group with write permission 如何使用Powershell从csv文件更新Active Directory中的更多数据行? - How can I update more data rows in Active Directory from a csv file using Powershell? Active Directory组成员-Powershell - Active Directory Group Members - Powershell 使用 Powershell 添加 Active Directory 组 - Adding an Active Directory group with Powershell 在Powershell中读取CSV文件以从Active Directory获取信息 - Reading CSV file in powershell to get info from Active directory Active Directory Powershell:Export-Csv 丢失了一些数据 - Active Directory Powershell : Export-Csv is missing out some data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM