Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor changes #59

Merged
merged 12 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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