-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy path12_3.ps1
More file actions
40 lines (40 loc) · 1.45 KB
/
12_3.ps1
File metadata and controls
40 lines (40 loc) · 1.45 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
function Set-TMServiceLogon {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,
ValueFromPipelineByPropertyName=$True)]
[string]$ServiceName,
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[string[]]$ComputerName,
[Parameter(ValueFromPipelineByPropertyName=$True)]
[string]$NewPassword,
[Parameter(ValueFromPipelineByPropertyName=$True)]
[string]$NewUser,
[string]$ErrorLogFilePath
)
BEGIN{}
PROCESS{
ForEach ($computer in $ComputerName) {
$option = New-CimSessionOption -Protocol Wsman
$session = New-CimSession -SessionOption $option `
-ComputerName $Computer
If ($PSBoundParameters.ContainsKey('NewUser')) {
$args = @{'StartName'=$NewUser
'StartPassword'=$NewPassword}
} Else {
$args = @{'StartPassword'=$NewPassword}
}
Invoke-CimMethod -ComputerName $computer `
-MethodName Change `
-Query "SELECT * FROM Win32_Service WHERE Name =
➥'$ServiceName'" `
-Arguments $args |
Select-Object -Property @{n='ComputerName';e={$computer}},
@{n='Result';e={$_.ReturnValue}}
$session | Remove-CimSession
} #foreach
} #PROCESS
END{}
} #function