-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy path10_3.ps1
More file actions
30 lines (30 loc) · 1.15 KB
/
10_3.ps1
File metadata and controls
30 lines (30 loc) · 1.15 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
function Set-TMServiceLogon {
Param(
[string]$ServiceName,
[string[]]$ComputerName,
[string]$NewPassword,
[string]$NewUser,
[string]$ErrorLogFilePath
)
ForEach ($computer in $ComputerName) {
$option = New-CimSessionOption -Protocol Wsman
$session = New-CimSession -SessionOption $option `
-ComputerName $Computer
If ($PSBoundParameters.ContainsKey('NewUser')) { #A
$args = @{'StartName'=$NewUser;
'StartPassword'=$NewPassword}
} Else {
$args = @{'StartPassword'=$NewPassword}
}
Invoke-CimMethod -ComputerName $computer `
-MethodName Change `
-Query "SELECT * FROM Win32_Service WHERE Name = '$ServiceName'" ` #B
-Arguments $args |
Select-Object -Property @{n='ComputerName';e={$computer}}, #C
@{n='Result';e={$_.ReturnValue}}
$session | Remove-CimSession
} #foreach
} #function
#A Uses PSBoundParameters
#B CIM query
#C Method result piped to Select-Object