Skip to content

Commit

Permalink
Merge pull request #59 from voytas75/v1.6.0-dev
Browse files Browse the repository at this point in the history
## 1.6.0 - 2019.04.09

### Added

- Aliases `Count`, `CountOnly` for parameter `Minimal`,
- Export results to JSON file, parameter `ExportJSON` and `ExportJSONpath`,
- Search for the exact user name, parameter `Strict`.

### Changed

- Clearing and formatting the code,
- Minor changes.
  • Loading branch information
voytas75 authored Apr 9, 2019
2 parents 2b194e7 + 9bd8e5c commit 1aac174
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 334 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.6.0 - 2019.04.09

### Added

- Aliases `Count`, `CountOnly` for parameter `Minimal`,
- Export results to JSON file, parameter `ExportJSON` and `ExportJSONpath`,
- Search for the exact user name, parameter `Strict`.

### Changed

- Clearing and formatting the code,
- Minor changes.

## 1.5.3 - 2019.04.09

### Changed
Expand Down
74 changes: 38 additions & 36 deletions Find-ServiceUser.ps1
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
Function Find-ServiceUser {
[CmdletBinding()]
param (
[parameter(mandatory=$true,position=0)]
[string[]]
$computer,
[CmdletBinding()]
param (
[parameter(mandatory = $true, position = 0)]
[string[]]
$computer,

[parameter(mandatory=$false,position=1)]
[string]
$user
)
$user = $user.trim()
$computer=$computer.trim()
if ([bool](Test-Connection -ComputerName $computer -Count 1 -ErrorAction SilentlyContinue)){
$filter = "startname like '%$($user)%'"
Write-Verbose -Message "WMI query for system services."
try {
$service_ = Get-CimInstance -classname win32_service -filter "$filter" -ComputerName $computer -ErrorAction Stop
}
catch {
Write-Error -Message "Failed WMI query for system services with Service Logon Account as ""$user"": $_"
[parameter(mandatory = $false, position = 1)]
[string]
$user,

[parameter(Mandatory = $false, HelpMessage = 'Turns on the search after the exact username.')]
[switch]
$Strict
)
$user = $user.trim()
$computer = $computer.trim()
if ([bool](Test-Connection -ComputerName $computer -Count 1 -ErrorAction SilentlyContinue)) {
if ($Strict) {
$filter = "startname = '$($user)'"
#Write-Information $filter -InformationAction Continue
} else {
$filter = "startname LIKE '%$($user)%'"
}
Write-Verbose -Message "WMI query for system services."
try {
$service_ = Get-CimInstance -classname win32_service -filter "$filter" -ComputerName $computer -ErrorAction Stop
}
catch {
Write-Error -Message "Failed WMI query for system services with Service Logon Account as ""$user"": $_"
}
if ($service_) {
Write-Verbose -Message "Return WMI query data"
return $service_
}
}
else {
Write-Verbose -Message "$computer`: Connection failed!"
Write-Information -MessageData "$computer`: Connection failed!" -InformationAction Continue
return $null
}
if ($service_) {
Write-Verbose -Message "Return WMI query data"
return $service_
#New-Object -TypeName psobject -Property @{`
#Server = $service_.Systemname;
#Servicename = $service_.Name;
#ServicePath = $service_.Pathname;
#ServiceDisplayName = $service_.Displayname;
#StartUser = $service_.Startname;
#ServiceState = $service_.state
#}
}
} else {
Write-verbose -Message "$computer`: Connection failed!"
Write-Information -MessageData "$computer`: Connection failed!" -InformationAction Continue
return $null
}
}# end function Find-ServiceUser
Loading

0 comments on commit 1aac174

Please sign in to comment.