-
Notifications
You must be signed in to change notification settings - Fork 40
/
Get-ServerOwner.ps1
96 lines (68 loc) · 3.04 KB
/
Get-ServerOwner.ps1
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function Get-ServerOwner {
<#
.SYNOPSIS
Returns the associated owner assigned for the specified server(s). Also included are the operating system name
and the location where the object resides in Active Directory
.DESCRIPTION
Returns the associated owner assigned for the specified server(s). Also included are the operating system name
and the location where the object resides in Active Directory
.PARAMETER ComputerName
The name of the computer you want to query. More than one computer can be entered by seperating each computername
should be with a comma.
.EXAMPLE
Get-ServerOwner SRV01
Name ManagedBy OperatingSystem CanonicalName
---- --------- --------------- -------------
SRV01 Michael_Kanakos Windows Server 2012 R2 Standard NWTraders.MSFT/Computers/SRV01
.EXAMPLE
Get-ServerOwner SRV01 | Format-List
Name : SRV01
ManagedBy : Michael_Kanakos
OperatingSystem : Windows Server 2012 R2 Standard
CanonicalName : NWTraders.MSFT/Computers/SRV01
.EXAMPLE
Get-ServerOwner Svr01, svr02, svr03 | Format-Table
Name ManagedBy OperatingSystem CanonicalName
---- --------- --------------- -------
SRV01 Michael_Kanakos Windows Server 2012 R2 Standard NWTraders.MSFT/Computers/SRV01
SRV02 Derek_Jeter Windows Server 2012 R2 Standard NWTraders.MSFT/Computers/SRV02
SRV03 Tom_Brady Windows Server 2012 R2 Standard NWTraders.MSFT/Computers/SRV03
.NOTES
Name: Get-ServerOwner
Author: Mike Kanakos
Version: 1.0.0
DateCreated: 2019-06-05
DateUpdated: 2019-09-17
v1.0.1 - fix broken code, add examples, add parameter, add foreach
.LINK
https://www.github.com/compwiz32/Powershell
#>
[CmdletBinding()]
Param(
[alias('DnsHostName', '__SERVER', 'Computer', 'IPAddress')]
[Parameter(Mandatory = $True, ValueFromPipeline = $true)]
[string[]]$ComputerName
)
begin {
} #end of begin
process {
foreach ($Node in $ComputerName) {
$ParamHash = @{
Identity = $Node
Properties = 'OperatingSystem',
'ManagedBy',
'CanonicalName',
'Enabled'
} #end ADUserParams
$SelectParams = @{
Property = 'Name',
@{Name = 'ManagedBy'; Expression = { (Get-ADUser ($_.managedBy)).samaccountname } },
'OperatingSystem',
'CanonicalName'
} #end SelectParams
Get-ADComputer @ParamHash | Where-Object { $_.enabled -eq $true } | Select-Object @SelectParams
} #end ForEach
} #end Process block
end {
} #end End block
} #end of Function