簡體   English   中英

在Active Directory AD Powershell中再次運行腳本所有計算機

[英]Run script agains all computer in Active Directory AD Powershell

我想問你如何針對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    ```

將AD的DNSHostName屬性添加到對象?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM