Showing posts with label service. Show all posts
Showing posts with label service. Show all posts

Monday, April 18, 2016

Powershell: Get services and accounts used to run them on all computers using Jobs


cls
####################
#By Tony Unger
#Purpose: inventory all services and user accounts running them with jobs
#
##
$myCol = @()
$i =0  
$servers = get-adcomputer -filter * | select -expand name 

$scriptblock = {
 param([string]$server)

get-wmiobject win32_service -computername $Server | select *

}

$ServersCount = $Servers.count

foreach($server in $Servers){
    $i++
    $running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
 Write-Progress -Activity "Gathering computer info" -status "Currently on $server -- $i of $ServersCount" -percentComplete ($i / $ServersCount*100)
 if ($running.Count -le 50) {
        Start-Job -ScriptBlock $scriptblock -Name $server -ArgumentList $server, $creds 
    } 
 else {
         $running | Wait-Job
    }
}

while ($running.Count -ge 1) {
      sleep 1 
    $running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
} 


foreach ($job in Get-Job ){

 $recjobs = Receive-Job -Keep -Job $job 
 foreach ($recjob in $recjobs){
    $Detail = New-Object PSObject 
     
  $Detail | Add-Member Noteproperty Caption $recjob.Caption
  $Detail | Add-Member Noteproperty Name $recjob.name 
  $Detail | Add-Member Noteproperty Startname $recjob.startname
        $Detail | Add-Member Noteproperty Server $recjob.__SERVER
  $myCol += $Detail

 }
}

Friday, November 21, 2014

SQL - If you don't have permission to logon fix

Purpose: If you don't want to put a SQL db into single user mode, you can try the following to give yourself permission to a SQL instance. The following will open a command prompt as the built in security principal "System" using PSExec. psexec -i -s -d cmd From there open SQL management studio from within that command prompt. ie: c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" I came up with this independently, but a simple google search will show you others have figured it out as well. Should be able to now give yourself permissions to log on now depending on how the SQL was initially configured. If this doesn't work you will have to Start the instance of SQL Server in single-user mode by using either the -m or -f options. Any member of the computer's local Administrators group can then connect to the instance of SQL Server as a member of the sysadmin fixed server role.

http://msdn.microsoft.com/en-us/library/dd207004.aspx

Tuesday, August 5, 2014

Powershell: Get list of all services accounts used on Windows servers in domain.


Purpose: This script will search AD for Windows Servers that are enabled and attempted to connect to each server and get a listing of all services and the accounts used to run them.
Note: This will take a while to run unless someone wants to make it multithreaded.
I just wrote this so there may need to be some bug fixes but in general it seemed to work.
Requirements: RSAT tools WMI



Import-Module activedirectory
cls

$ServicesReport = @()

$AllServers = Get-ADComputer -Filter {(OperatingSystem -Like "Windows Server*")-and (enabled -eq "true")} -Property SamAccountName | select -expand Name

$i = 0
foreach($Server in $AllServers) {
$i++
Write-Host "Working on Server: $Server " $i " of " $AllServers.Count 

try
{
if (Test-Connection -ComputerName $Server -Quiet) {
$Services = Get-WmiObject win32_service -ComputerName $Server | select Name,
  @{N="StartupType";E={$_.StartMode}},
  @{N="ServiceAccount";E={$_.StartName}},
  @{N="SystemName";E={$_.Systemname}}
    foreach ($Service in $Services) {
       $Detail = New-Object PSObject 
    $Detail | Add-Member Noteproperty ServiceName $($Service.Name)
    $Detail | Add-Member Noteproperty StartupType $Service.StartupType
    $Detail | Add-Member Noteproperty ServiceAccount $Service.ServiceAccount
    $Detail | Add-Member Noteproperty SystemName $Service.Systemname
       $ServicesReport += $Detail
    }
 }
}
Catch
{
$Detail = New-Object PSObject 
    $Detail | Add-Member Noteproperty ServiceName "NA"
    $Detail | Add-Member Noteproperty StartupType "NA"
    $Detail | Add-Member Noteproperty ServiceAccount "Error"
    $Detail | Add-Member Noteproperty SystemName $Server
       $ServicesReport += $Detail
  
 }
  
  } 
  
$ServicesReport | Export-Csv -Path c:\temp\test.csv -NoTypeInformation


Powershell: Microsoft Graph to add new roles to application registration

PowerShell Script Bulk add new roles to application registration in azure. Update $roles with ,Us...