-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ServerDetails.Ps1
More file actions
52 lines (48 loc) · 1.81 KB
/
Get-ServerDetails.Ps1
File metadata and controls
52 lines (48 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<#
.Synopsis
Lists Os Information, IP's, and Roles of (a) given Server(s)
.DESCRIPTION
Provides Os Version, Build Number, and OS Architecture; A & AAAA Records from DNS; All Roles
.EXAMPLE
Get-ServerDetails -FilePath "C:\Output.txt" -Servers $servers
.EXAMPLE
Get-ServerDetails -Servers $(Get-AdServers)
.EXAMPLE
Get-ServerDetails -Servers $(Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*'} -SearchBase $((Get-ADDomain).DistinguishedName))
.ROLE
JakesSysadminFunctions
.FUNCTIONALITY
Get Server Details
#>
Function Get-ServerDetails{
[CmdletBinding()] #Enable all the default paramters, including -Verbose
[Alias()]
Param(
[string[]]$FilePath,
$Servers
)
$results = foreach ($server in $servers) {
$details = Get-WmiObject Win32_OperatingSystem -ComputerName $server.dnshostname | Select PSComputerName, Caption, OSArchitecture, Version, BuildNumber
$ip = Resolve-DnsName $server.dnshostname -Server 10.100.0.222
$roles =Get-WindowsFeature -ComputerName $server.dnshostname
if ($?){
}else {
$roles = Invoke-Command -ComputerName $server.dnshostname -ScriptBlock {ServerManagerCmd.exe -query}
$roles = $roles[4..($roles.Length-1)]
}
[PSCustomObject]@{
DnsName = $server.DNSHostName
Details = $details
IPs = $ip
Roles = $roles
}
}
$formated = $results | ForEach-Object {
"----------------------------------------------------------------------------------------------------------------------------"
$_.DnsName
$_.details | ft
$_.Ips | ft
$_.Roles
"----------------------------------------------------------------------------------------------------------------------------"
}
}