【问题标题】:Run script agains all computer in Active Directory AD Powershell对 Active Directory AD Powershell 中的所有计算机运行脚本
【发布时间】:2019-06-11 19:48:53
【问题描述】:

我想问你如何在 AD 中的所有计算机上运行我的 PowerShell 脚本。我尝试将所有计算机名称设置为变量,然后运行脚本 foreach,但我无法从变量中找出计算机名称到我的脚本中。

感谢您的帮助

$HostName  =  @{n="Hostname";e={[System.Net.Dns]::GetHostName()}}
# IP
$IP  =  @{n="IP";e={gwmi Win32_NetworkAdapterConfiguration -filter 'IPEnabled=True'|select -expandproperty IPAddress|Where {$_ -notmatch ':'}}}
#MAC
$MAC  =  @{n="MAC";e={get-wmiobject -class "Win32_NetworkAdapterConfiguration" |Where{$_.IpEnabled -Match "True"} |select MACAddress}}
#OS
$OS  =  @{n="OS";e={(Get-WMIObject win32_operatingsystem).name}}
#UserLogin
$UserProperty = @{n="user";e={(New-Object System.Security.Principal.SecurityIdentifier $_.ReplacementStrings[1]).Translate([System.Security.Principal.NTAccount])}}
#Log ON / Log OFF
$TypeProperty = @{n="Action";e={if($_.EventID -eq 7001) {"Logon"} else {"Logoff"}}}
#TIME
$TimeProeprty = @{n="Time";e={$_.TimeGenerated}}
#SELECT 
Get-EventLog System -Source Microsoft-Windows-Winlogon| Where { $_.TimeGenerated -GT (Get-Date).AddDays(-30) } | select $UserProperty,$TypeProperty,$TimeProeprty,$HostName,$IP,$MAC,$OS    ```

【问题讨论】:

  • 您可以使用组策略在所有计算机上运行它或使用 Invoke-Command。系统名称保存在环境变量 $Env:COMPUTERNAME
  • @I.T Delinquent 它不起作用 $Computer = (Get-ADComputer -filter *).Name Invoke-Command -ComputerName $computers {

标签: powershell


【解决方案1】:

将 AD 中的 DNSHostName 属性添加到对象?

$Computers = Get-ADComputer -Filter * -properties DNSHostName
$HostName  =  @{n="Hostname";e={$computers.DNSHostName}}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 2023-01-19
    • 2017-06-02
    • 1970-01-01
    相关资源
    最近更新 更多