[英]Report log software restriction from all computers in domain
如何使用$ computers变量在所有cpu get-winevent中执行以下示例中的示例?
Get-WinEvent -FilterHashTable @{LogName= "Application"; ProviderName="Microsoft-Windows-SoftwareRestrictionPolicies";StartTime=$StartTime} -ErrorAction SilentlyContinue
$Computers = get-adcomputer -SearchBase "OU=Workstations,DC=FQDN,DC=local" -filter * -Properties MemberOf | where-object {[string]$_.memberof -notmatch 'CN=NPS' } | select Name | Format-Table -HideTableHeaders | Out-File C:\Users\user\Desktop\cpu1.txt
gc C:\Users\user\Desktop\cpu1.txt | where {$_ -ne ""} > C:\Users\user\Desktop\cpu2.txt
$cpu = Get-Content C:\Users\user\Desktop\cpu2.txt
$a = New-PSSession -ComputerName $cpu
我尝试使用enter-pssession -computername $ cpu或enter-pssession -session $ a,但这不起作用。
我在下面使用invoke-command:
Invoke-Command -ComputerName $cpu -ScriptBlock {Get-WinEvent -FilterHashTable @{LogName= "Application"; ProviderName="Microsoft-Windows-SoftwareRestrictionPolicies";StartTime=$StartTime}}
但是我有这个错误:
A null value was encountered in the StartTime hash table key. Null values are not permitted.
+ CategoryInfo : InvalidArgument: (StartTime:String) [Get-WinEvent], Exception
+ FullyQualifiedErrorId : NullNotAllowedInHashtable,Microsoft.PowerShell.Commands.GetWinEventCommand
+ PSComputerName : computername
我正在尝试将所有cpu的日志复制到csv文件。
问题是, $StartTime
不可里面-ScriptBlock
范围。 您需要为其提供ArgumentList
,例如:
Invoke-Command -ComputerName $cpu -ScriptBlock {param($StartTime) Get-WinEvent -FilterHashTable @{LogName= "Application"; ProviderName="Microsoft-Windows-SoftwareRestrictionPolicies";StartTime=$StartTime}} -ArgumentList $StartTime
在旁注中,下次请简化您的示例,因为我们对您获取计算机的方式并不真正感兴趣
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.