-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy path13_5.ps1
More file actions
48 lines (48 loc) · 1.72 KB
/
13_5.ps1
File metadata and controls
48 lines (48 loc) · 1.72 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
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}
}
$params = @{'CimSession'=$session
'MethodName'='Change'
'Query'="SELECT * FROM Win32_Service " +
"WHERE Name = '$ServiceName'"
'Arguments'=$args}
$ret = Invoke-CimMethod @params
switch ($ret.ReturnValue) {
0 { $status = "Success" }
22 { $status = "Invalid Account" }
Default { $status = "Failed: $($ret.ReturnValue)" }
}
$props = @{'ComputerName'=$computer
'Status'=$status}
$obj = New-Object -TypeName PSObject -Property $props
Write-Output $obj
$session | Remove-CimSession
} #foreach
} #PROCESS
END{}
} #function