从两个单独的集合中创建一个报告

时间:2018-06-26 05:24:16

标签: powershell

我缺少PowerShell中的一些基本知识。

我有一个脚本,该脚本生成两个集合,一个是计算机名称,其中包含特定应用程序的版本详细信息,另一个是从计算机名称列表中获取的用户名列表,因为用户名在计算机名称中,例如计算机名称是:

XXXXXX02jbloggs

此计算机的所有者为jbloggs,jbloggs是有效的AD对象,其全名是joe博客。

该脚本的最终目标是生成一个包含计算机名称,所有者SamAccountName,全名和应用程序详细信息的报告,脚本将专门检查这些报告。

例如,

  

此计算机范围内存在什么版本的Adobe Reader

到目前为止,我有:

$ErrorActionPreference = "SilentlyContinue"

$Computers = Get-ADComputer -Server BlahBlah.com -Filter {name -like "XXXXXX02*"} | 
Select-Object -ExpandProperty Name

$Users = $Computers -Replace '\D*\d*(\w*)', '$1'

$Results = foreach ($Computer in $Computers) {
    Get-CimInstance -ComputerName $Computer -ClassName Win32_Product | 
    Where-Object{$_.Name -like "*Adobe Reader*"} | 
    Select-Object PSComputerName, Name, Version, InstallDate 
}

$FullNames = ForEach ($user in $Users) {
    Get-ADUser -Server BlahBlah.com -Identity $User -Properties * | 
    Select-Object -ExpandProperty Name
} 
  • $Results为我提供了计算机名称,Adobe Reader xxx,版本和安装日期的列表。
  • $FullNames为我提供了基于其用户ID的全名列表

我不知道如何构造脚本,因此它会产生全名,用户名,计算机名,应用程序名和安装日期。

这就是为什么我说我缺少PowerShell的一些基本知识,我一直在关注自定义对象,嵌套循环和其他想法,但无济于事。当我需要完成几个类似的示例时,确实需要寻找有关此类问题的建议。 任何建议将不胜感激。

1 个答案:

答案 0 :(得分:5)

  • {"Session":{"MediaStartTime":"2018-06-13T00:53:31.023","MediaEndTime":"2018-06-13T01:12:27.0251","IsFromReceived":true,"IsToReceived":true,"ConferenceUri":null,"MediationServerBypassFlag":false,"FromOS":"Windows 10.0.15063 SP: 0.0 Type: 1(Workstation) Suite: 256 Arch: x64 WOW64: True","ToOS":"","FromCPUName":"Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz","ToCPUName":"","FromCPUNumberOfCores":null,"ToCPUNumberOfCores":2,"FromCPUProcessorSpeed":2701,"ToCPUProcessorSpeed":2501,"FromVirtualizationFlag":null,"ToVirtualizationFlag":null,"PossibleDataMissing":false},"MediaLines":[{"MediaLineLabelText":"main-audio","MidCallReport":false,"FromConnectivityIce":"","ToConnectivityIce":"DIRECT","Transport":"UDP","Security":"SRTP","FromPort":50010,"ToPort":50003,"FromRelayIPAddr":"52.113.2.161","ToRelayIPAddr":"52.113.2.165","FromRelayPort":null,"ToRelayPort":51623,"FromCaptureDev":"Headset Microphone (Plantronics C310-M)","ToCaptureDev":"Headset Microphone (Plantronics C310-M)","FromCaptureDevDriver":"Microsoft: 10.0.15063.502","ToCaptureDevDriver":"Microsoft: 6.1.7601.18208","FromRenderDev":"Headset Earphone (Plantronics C310-M)","ToRenderDev":"Headset Earphone (Plantronics C310-M)","FromRenderDevDriver":"Microsoft: 10.0.15063.502","ToRenderDevDriver":"Microsoft: 6.1.7601.18208","FromVPN":false,"ToVPN":false,"FromLinkSpeed":130000000,"ToLinkSpeed":36000000,"FromNetworkConnectionDetail":"wifi","ToNetworkConnectionDetail":"wifi","FromIPAddr":"192.168.1.55","ToIPAddr":"88.168.20.106","FromBssid":"1890d8d727d0","ToBssid":"f22695127d94","FromReflexiveLocalIPAddr":"176.136.98.193","ToReflexiveLocalIPAddr":"88.168.20.106","FromWifiDriverDeviceDesc":"Microsoft Wi-Fi Direct Virtual Adapter;Intel(R) Dual Band Wireless-AC 8265","ToWifiDriverDeviceDesc":"Intel(R) Dual Band Wireless-AC 8260;Microsoft Virtual WiFi Miniport Adapter","FromWifiDriverVersion":"Microsoft:10.0.15063.0;Intel:19.1.0.4","ToWifiDriverVersion":"Intel:18.12.0.3;Microsoft:6.1.7600.16385","FromWifiRSSI":0,"ToWifiRSSI":0,"FromSSID":"42626f782d4537353541423731","ToSSID":"66726565626f78656e747265","FromWifiChannel":1,"ToWifiChannel":1,"FromActivePowerProfile":0,"ToActivePowerProfile":0,"FromWifiHandovers":0,"ToWifiHandovers":0,"FromWifiChannelSwitches":0,"ToWifiChannelSwitches":0,"FromWifiChannelReassociations":0,"ToWifiChannelReassociations":0,"FromWifiRadioFrequency":0,"ToWifiRadioFrequency":0,"FromWifiSignalStrength":99,"ToWifiSignalStrength":88,"PossibleDataMissing":false},{"MediaLineLabelText":"main-video","MidCallReport":false,"FromConnectivityIce":"","ToConnectivityIce":"DIRECT","Transport":"UDP","Security":"SRTP","FromPort":50022,"ToPort":50039,"FromRelayIPAddr":"52.113.2.153","ToRelayIPAddr":"52.113.2.169","FromRelayPort":null,"ToRelayPort":54941,"FromCaptureDev":"Integrated Webcam","ToCaptureDev":"Integrated Webcam","FromCaptureDevDriver":"","ToCaptureDevDriver":"","FromRenderDev":"Intel(R) HD Graphics 620","ToRenderDev":"Intel(R) HD Graphics 520","FromRenderDevDriver":"Intel Corporation:21.20.16.4627","ToRenderDevDriver":"Intel Corporation:20.19.15.4390","FromVPN":false,"ToVPN":false,"FromLinkSpeed":130000000,"ToLinkSpeed":36000000,"FromNetworkConnectionDetail":"wifi","ToNetworkConnectionDetail":"wifi","FromIPAddr":"192.168.1.55","ToIPAddr":"88.168.20.106","FromBssid":"1890d8d727d0","ToBssid":"f22695127d94","FromReflexiveLocalIPAddr":"176.136.98.193","ToReflexiveLocalIPAddr":"88.168.20.106","FromWifiDriverDeviceDesc":"Microsoft Wi-Fi Direct Virtual Adapter;Intel(R) Dual Band Wireless-AC 8265","ToWifiDriverDeviceDesc":"Intel(R) Dual Band Wireless-AC 8260;Microsoft Virtual WiFi Miniport Adapter","FromWifiDriverVersion":"Microsoft:10.0.15063.0;Intel:19.1.0.4","ToWifiDriverVersion":"Intel:18.12.0.3;Microsoft:6.1.7600.16385","FromWifiRSSI":0,"ToWifiRSSI":0,"FromSSID":"42626f782d4537353541423731","ToSSID":"66726565626f78656e747265","FromWifiChannel":1,"ToWifiChannel":1,"FromActivePowerProfile":0,"ToActivePowerProfile":0,"FromWifiHandovers":0,"ToWifiHandovers":0,"FromWifiChannelSwitches":0,"ToWifiChannelSwitches":0,"FromWifiChannelReassociations":0,"ToWifiChannelReassociations":0,"FromWifiRadioFrequency":0,"ToWifiRadioFrequency":0,"FromWifiSignalStrength":99,"ToWifiSignalStrength":88,"PossibleDataMissing":false}],"AudioStreams":[{"JitterInterArrival":9,"JitterInterArrivalMax":22,"PacketLossRate":0.003282649,"PacketLossRateMax":0.4927536,"BurstDensity":null,"BurstDuration":null,"BurstGapDensity":null,"BurstGapDuration":null,"BandwidthEst":3977162,"RoundTrip":94,"RoundTripMax":324,"PacketUtilization":32194,"RatioConcealedSamplesAvg":0.008398115,"ConcealedRatioMax":0.2057942,"PayloadDescription":"SILKWide","AudioSampleRate":16000,"AudioFECUsed":false,"SendListenMOS":3.33,"OverallAvgNetworkMOS":4.163474,"DegradationAvg":0.1265264,"DegradationMax":1.078434,"NetworkJitterAvg":29.02976,"NetworkJitterMax":188.6704,"JitterBufferSizeAvg":101,"JitterBufferSizeMax":273,"PossibleDataMissing":false,"StreamDirection":"FROM-to-TO"},{"JitterInterArrival":9,"JitterInterArrivalMax":22,"PacketLossRate":0.003282547,"PacketLossRateMax":0.4927536,"BurstDensity":null,"BurstDuration":null,"BurstGapDensity":null,"BurstGapDuration":null,"BandwidthEst":626065,"RoundTrip":72,"RoundTripMax":1249,"PacketUtilization":32292,"RatioConcealedSamplesAvg":0.008398115,"ConcealedRatioMax":null,"PayloadDescription":"SILKWide","AudioSampleRate":16000,"AudioFECUsed":true,"SendListenMOS":3.29,"OverallAvgNetworkMOS":null,"DegradationAvg":null,"DegradationMax":null,"NetworkJitterAvg":null,"NetworkJitterMax":null,"JitterBufferSizeAvg":null,"JitterBufferSizeMax":null,"PossibleDataMissing":false,"StreamDirection":"TO-to-FROM"}],"VideoStreams":[{"PossibleDataMissing":false,"VideoMediaLineLabelText":"main-video","JitterInterArrival":1,"JitterInterArrivalMax":19,"PacketLossRate":0.0002356738,"PacketLossRateMax":0.009090909,"BandwidthEst":2598927,"RoundTrip":81,"RoundTripMax":545,"PacketUtilization":55181,"PayloadDescription":"H264","VideoResolution":"424x240","VideoBitRateAvg":184640,"VideoBitRateMax":329133,"VideoFrameRateAvg":7.494197,"VideoPacketLossRate":0.0002356738,"VideoFrameLossRate":191.9469,"CIFQualityRatio":76,"VGAQualityRatio":3,"HD720QualityRatio":20,"NoneDropRatio":null,"SendCodecTypes":"","SendResolutionWidth":null,"SendResolutionHeight":null,"SendFrameRateAverage":12.81255,"SendBitRateMaximum":null,"SendBitRateAverage":null,"SendVideoStreamsMax":null,"VideoPostFECPLR":0.0001450063,"RecvCodecTypes":"H264 SW","RecvResolutionWidth":1280,"RecvResolutionHeight":720,"RecvFrameRateAverage":7.49366,"RecvBitRateMaximum":2350453,"RecvBitRateAverage":667126,"DynamicCapabilityPercent":0.0,"LowBitRateCallPercent":0.0,"LowFrameRateCallPercent":45.53571,"LowResolutionCallPercent":null,"DurationSeconds":1128.574,"IsAggregatedData":true,"UseForCallClassification":true,"StreamDirection":"FROM-to-TO"},{"PossibleDataMissing":false,"VideoMediaLineLabelText":"main-video","JitterInterArrival":1,"JitterInterArrivalMax":19,"PacketLossRate":0.000237157,"PacketLossRateMax":0.009090909,"BandwidthEst":778259,"RoundTrip":73,"RoundTripMax":531,"PacketUtilization":55170,"PayloadDescription":"H264","VideoResolution":"424x240","VideoBitRateAvg":210845,"VideoBitRateMax":445636,"VideoFrameRateAvg":7.499987,"VideoPacketLossRate":0.000237157,"VideoFrameLossRate":null,"CIFQualityRatio":null,"VGAQualityRatio":null,"HD720QualityRatio":null,"NoneDropRatio":null,"SendCodecTypes":"H264 HW","SendResolutionWidth":424,"SendResolutionHeight":240,"SendFrameRateAverage":7.499987,"SendBitRateMaximum":445636,"SendBitRateAverage":210845,"SendVideoStreamsMax":1,"VideoPostFECPLR":null,"RecvCodecTypes":"","RecvResolutionWidth":null,"RecvResolutionHeight":null,"RecvFrameRateAverage":null,"RecvBitRateMaximum":null,"RecvBitRateAverage":null,"DynamicCapabilityPercent":1.0,"LowBitRateCallPercent":null,"LowFrameRateCallPercent":null,"LowResolutionCallPercent":null,"DurationSeconds":1120.002,"IsAggregatedData":false,"UseForCallClassification":true,"StreamDirection":"TO-to-FROM"}],"AudioSignals":[{"PossibleDataMissing":false,"SubmittedByFromUser":false,"SendSignalLevel":-23,"RecvSignalLevel":-20,"SendNoiseLevel":-68,"RecvNoiseLevel":-61,"AudioSpeakerGlitchRate":0,"AudioMicGlitchRate":0,"VsEntryCauses":"","EchoEventCauses":"","RecvSignalLevelCh1":-20,"RecvSignalLevelCh2":null,"RecvNoiseLevelCh1":-61,"RecvNoiseLevelCh2":null,"SendSignalLevelCh1":-23,"SendSignalLevelCh2":null,"SendNoiseLevelCh1":-68,"SendNoiseLevelCh2":null,"RenderSignalLevel":0.0,"RenderNoiseLevel":0.0,"RenderLoopbackSignalLevel":-19.30759},{"PossibleDataMissing":false,"SubmittedByFromUser":true,"SendSignalLevel":-20,"RecvSignalLevel":-23,"SendNoiseLevel":-63,"RecvNoiseLevel":-64,"AudioSpeakerGlitchRate":0,"AudioMicGlitchRate":0,"VsEntryCauses":"","EchoEventCauses":"","RecvSignalLevelCh1":-23,"RecvSignalLevelCh2":null,"RecvNoiseLevelCh1":-64,"RecvNoiseLevelCh2":null,"SendSignalLevelCh1":-20,"SendSignalLevelCh2":null,"SendNoiseLevelCh1":-63,"SendNoiseLevelCh2":null,"RenderSignalLevel":0.0,"RenderNoiseLevel":0.0,"RenderLoopbackSignalLevel":-23.17426}],"AppSharingStreams":null,"FeedBackReports":null,"AudioClientEvents":[{"PossibleDataMissing":false,"SubmittedByFromUser":false,"NetworkSendQualityEventRatio":0.03,"NetworkReceiveQualityEventRatio":0.0,"NetworkDelayEventRatio":0.0,"NetworkBandwidthLowEventRatio":0.0,"CPUInsufficientEventRatio":0.0,"DeviceHalfDuplexAECEventRatio":0.0,"DeviceRenderNotFunctioningEventRatio":0.0,"DeviceCaptureNotFunctioningEventRatio":0.0,"DeviceGlitchesEventRatio":0.0,"DeviceLowSNREventRatio":0.0,"DeviceLowSpeechLevelEventRatio":0.0,"DeviceClippingEventRatio":0.03,"DeviceEchoEventRatio":0.0,"DeviceNearEndToEchoRatioEventRatio":0.0,"DeviceMultipleEndpointsEventCount":0,"DeviceHowlingEventCount":0,"DeviceRenderZeroVolumeEventRatio":0.0,"DeviceRenderMuteEventRatio":0.0},{"PossibleDataMissing":false,"SubmittedByFromUser":true,"NetworkSendQualityEventRatio":0.0,"NetworkReceiveQualityEventRatio":0.03,"NetworkDelayEventRatio":0.0,"NetworkBandwidthLowEventRatio":0.0,"CPUInsufficientEventRatio":0.0,"DeviceHalfDuplexAECEventRatio":0.0,"DeviceRenderNotFunctioningEventRatio":0.0,"DeviceCaptureNotFunctioningEventRatio":0.0,"DeviceGlitchesEventRatio":0.0,"DeviceLowSNREventRatio":0.0,"DeviceLowSpeechLevelEventRatio":0.0,"DeviceClippingEventRatio":0.0,"DeviceEchoEventRatio":0.0,"DeviceNearEndToEchoRatioEventRatio":0.0,"DeviceMultipleEndpointsEventCount":0,"DeviceHowlingEventCount":0,"DeviceRenderZeroVolumeEventRatio":0.0,"DeviceRenderMuteEventRatio":0.0}],"VideoClientEvents":[{"PossibleDataMissing":false,"VideoMediaLineLabel":"main-video","SubmittedByFromUser":false,"NetworkBandwidthLowEventRatio":0.0,"NetworkReceiveQualityEventRatio":0.0},{"PossibleDataMissing":false,"VideoMediaLineLabel":"main-video","SubmittedByFromUser":true,"NetworkBandwidthLowEventRatio":0.0,"NetworkReceiveQualityEventRatio":0.0}],"TraceRoutes":[{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":false,"Hop":0,"IPAddress":"192.168.0.254","RTT":2},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":false,"Hop":1,"IPAddress":"88.168.20.254","RTT":57},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":false,"Hop":2,"IPAddress":"78.254.5.62","RTT":57},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":false,"Hop":3,"IPAddress":"78.254.255.161","RTT":59},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":false,"Hop":4,"IPAddress":"194.149.163.157","RTT":63},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":false,"Hop":5,"IPAddress":"194.149.163.90","RTT":62},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":false,"Hop":6,"IPAddress":"194.117.192.9","RTT":62},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":false,"Hop":7,"IPAddress":"212.194.171.144","RTT":65},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":false,"Hop":8,"IPAddress":"212.194.171.5","RTT":65},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":true,"Hop":0,"IPAddress":"192.168.1.254","RTT":4},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":true,"Hop":1,"IPAddress":"10.108.238.2","RTT":10},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":true,"Hop":2,"IPAddress":"212.194.171.4","RTT":13},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":true,"Hop":3,"IPAddress":"212.194.171.145","RTT":10},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":true,"Hop":5,"IPAddress":"194.149.162.85","RTT":13},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":true,"Hop":6,"IPAddress":"194.149.163.170","RTT":12},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":true,"Hop":7,"IPAddress":"78.254.255.162","RTT":12},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":true,"Hop":8,"IPAddress":"78.254.5.40","RTT":12},{"PossibleDataMissing":false,"TraceRouteMediaLineLabelText":"main-audio","SubmittedByFromUser":true,"Hop":9,"IPAddress":"88.168.20.106","RTT":58}]} 中获得一个当前用户,而不是创建两个单独的foreach。
  • 将计算所得的属性添加到选择中以在其中包含foreach($computer in $Computers) $ Result

FullName