How can merge 3 cycle in one script. And export in one table
server | Name | Cluster | TcpTestSucceeded | PingSucceeded | RemoteAddress | |
---|---|---|---|---|---|---|
Cell 1 | Cell 22 | Cell 11 | Cell 2 | Cell 21 | Cell 13 | Cell 27 |
Cell 3 | Cell 44 | Cell 33 | Cell 4 | Cell 41 | Cell 33 | Cell 47 |
Getting a list of email by DisplayName in AD
Import-Module ActiveDirectory
# path to file
$CSVpatch = "C:\temp\address.csv"
# Get
$result = Import-Csv -Path $CSVpatch -Delimiter ";" -Encoding Default | ForEach-Object {
$server = $_.server
Get-ADUser -Filter "DisplayName -eq '$($_.name)'" -Properties DisplayName, EmailAddress |
Select-Object @{Name = 'server'; Expression = {$server}},
@{Name = 'name'; Expression = {$_.DisplayName}},
@{Name = 'email'; Expression = {$_.EmailAddress}}
}
# format and export
$result | Format-Table -AutoSize
# export
$result | Export-Csv -Path 'C:\Temp\table.csv' -Encoding Default -NoTypeInformation -UseCulture
Getting a list of Cluster by Description in AD
# path to file
$CSVpatch = "C:\temp\address.csv"
# Get
$result = Import-Csv -Path $CSVpatch -Delimiter ";" -Encoding Default | ForEach-Object {
$server = $_.server
Get-ADComputer -Identity $server -Properties * |
Select-Object @{Name = 'server'; Expression = {$server}},
@{Name = 'Cluster'; Expression = {$_.Description}}
}
# format and export
$result | ft -AutoSize
# export
$result | Export-Csv -Path 'C:\Temp\table.csv' -Encoding Default -NoTypeInformation -UseCulture
Checking the availability of the server on a specific port, ping and ip
# path to file
$CSVpatch = "C:\temp\address.csv"
# Get
$result = Import-Csv -Path $CSVpatch -Delimiter ";" -Encoding Default | ForEach-Object {
$server = $_.server
Test-NetConnection -ComputerName $server -Port 13000 |
Select-Object @{Name = 'server'; Expression = {$server}},
@{Name = 'TcpTestSucceeded'; Expression = {$_.TcpTestSucceeded}},
@{Name = 'PingSucceeded'; Expression = {$_.PingSucceeded}},
@{Name = 'RemoteAddress'; Expression = {$_.RemoteAddress}}
}
# format and export
$result | ft -AutoSize
# export
$result | Export-Csv -Path 'C:\Temp\table.csv' -Encoding Default -NoTypeInformation -UseCulture