Posted On March 29, 2019

List Autorun Services

kimconnect 0 comments
blog.KimConnect.com >> Codes , Windows >> List Autorun Services
# $cred = get-Credential -credential kdoan-a
$Username = 'kimconnect\kim-Admin
$Password = 'PASSWORD'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$pass 

# Initialize
$servers="servero1","server02"
$services=""
$output=""

# List all currently running services on remote hosts > output to comma delimited strings
function listServices{
Foreach ($server in $servers){
    $runningServices=Invoke-Command -ComputerName $server -Credential $cred -ScriptBlock {Get-WmiObject win32_service -Filter "State='running' AND StartMode='Auto'"};
    $runningServices='"{0}"' -f ($runningServices.name -join '","')
    $output+=@(($server),($runningServices))
    }
    $output    
}
listServices 

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

SQL AlwayOn High Availability Default Port

Internal SQL DEV & QA environments may have SQL listening to the default port of…

PowerShell: Check Registry Path, Key, and Dword Value

$path='HKLM:\Software\Intel' $keyName='GMM' $dwordName='DedicatedSegmentSize' $dwordValue=512 Function CheckRegistryKey { param( [Parameter(Position = 0, Mandatory = $true)][String]$path, [Parameter(Position…

PowerShell: Search for Hyper-V Guest VM That Has Not Been Registered In Cluster

# findVmHost.ps1 $vmName='TESTVM01' function findVmHost($vmName){ try{ Import-Module Hyper-V Import-Module FailoverClusters $allHyperVHosts={(Get-ClusterNode | Where { $_.State…