【问题标题】:powershell active directory excel reportpowershell活动目录excel报告
【发布时间】:2020-04-27 05:25:13
【问题描述】:

我有这两个脚本

$Path = 'C:\Users\akouyoumjian\Desktop\Report4.csv'
Get-ADUser -Filter {enabled -eq $true} -Properties LastLogonTimeStamp | 

Select-Object Name,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp).ToString('yyyy-MM-dd_hh:mm:ss')}} | Export-Csv -Path $Path –notypeinformation

还有这个:

Get-ADComputer -Filter {(OperatingSystem -like "windows 7") -and (Enabled -eq "True")} -Properties OperatingSystem | Sort Name | select -Unique OperatingSystem

我想将它们合并到一个文件中 谢谢

【问题讨论】:

  • 您希望输出是什么样的?
  • 为什么你认为os version是一个AD用户属性?
  • 示例:Name(用户名)Stamp(上次日志的时间)OperationSystem(Windows 7)
  • 或者如果有办法将操作系统添加到第二个命令
  • 请用几行您期望输出的样例数据更新您的问题。请非常具体。

标签: powershell active-directory


【解决方案1】:

在这里找到的答案是否有效:https://stackoverflow.com/a/27893253/10542366

这会将所有文件附加在一起,一次一个地读取它们:

get-childItem "YOUR_DIRECTORY\*.txt" 
| foreach {[System.IO.File]::AppendAllText
 ("YOUR_DESTINATION_FILE", [System.IO.File]::ReadAllText($_.FullName))}

如果您需要,这将在每个文件条目的末尾放置一个新行:

get-childItem "YOUR_DIRECTORY\*.txt" | foreach
{[System.IO.File]::AppendAllText("YOUR_DESTINATION_FILE", 
[System.IO.File]::ReadAllText($_.FullName) + [System.Environment]::NewLine)}

跳过第一行:

$getFirstLine = $true

get-childItem "YOUR_DIRECTORY\*.txt" | foreach {
    $filePath = $_

    $lines =  $lines = Get-Content $filePath  
    $linesToWrite = switch($getFirstLine) {
           $true  {$lines}
           $false {$lines | Select -Skip 1}

    }

    $getFirstLine = $false
    Add-Content "YOUR_DESTINATION_FILE" $linesToWrite
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多