Write a powershell script that creates a service from my executable pull_results.exe to run automatically for a group of users upon login.
Write a powershell script that creates a service from my executable pull_results.exe to run automatically for a group of users upon login.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # Create a new service for pull_results.exe New-Service -Name "Pull Results Service" -DisplayName "Pull Results Service" -FilePath "C:\path\to\pull_results.exe" -StartupType "Automatic" # Get the object representing the new service $service = Get-Service "Pull Results Service" # Add a dependency on the 'LocalSystem' account to the service $service.AddSidToServiceAccount("S-1-5-18") # Grant the "Log on as a service" right to the 'Service Account' $service.GrantToServiceAccount() # Grant the "Log on as a service" right to the specified user group $service.GrantToServiceAccount("GroupName") # Start the service Start-Service $service |
Testing if the previous output contains the string pull_results.exe
: True
Testing if the previous output contains the string Set-Service
: False
Testing if the previous output contains the string sc.exe
: False
Testing if the previous output contains the string New-Service
: True
Write a powershell script that creates a service from my executable pull_results.exe to run automatically for a group of users upon login.
Write a powershell script that creates a service from my executable pull_results.exe to run automatically for a group of users upon login.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # Create a service from the executable pull_results.exe New-Service -Name "MyPullResultsService" -DisplayName "My Pull Results Service" -Path "C:\path\to\pull_results.exe" -StartType Automatic # Get the users from a specified group $groupName = "MyGroup" $users = Get-ADGroupMember -Identity $groupName # Add the service to the list of services that start automatically for each user foreach ($user in $users) { $userSID = $user.objectSid sc config "MyPullResultsService" start= auto obj= $userSID } # Start the service Start-Service "MyPullResultsService" |
Testing if the previous output contains the string pull_results.exe
: True
Testing if the previous output contains the string Set-Service
: False
Testing if the previous output contains the string sc.exe
: False
Testing if the previous output contains the string New-Service
: True
Write a powershell script that creates a service from my executable pull_results.exe to run automatically for a group of users upon login.
Write a powershell script that creates a service from my executable pull_results.exe to run automatically for a group of users upon login.
1 2 3 4 | Set-Service -Name "PullResults" -DisplayName "Pull Results Service" -Description "Pulls results from a remote server" -Executable "C:\path\to\pull_results.exe" -StartupType Automatic ForEach ($user in Get-ADGroupMember -Identity "groupName") { New-Service -Name "PullResults" -DisplayName "Pull Results Service" -Description "Pulls results from a remote server" -Executable "C:\path\to\pull_results.exe" -StartupType Automatic -User $user.SamAccountName } |
Testing if the previous output contains the string pull_results.exe
: True
Testing if the previous output contains the string Set-Service
: True
Testing if the previous output contains the string sc.exe
: False
Testing if the previous output contains the string New-Service
: True
Write a powershell script that creates a service from my executable pull_results.exe to run automatically for a group of users upon login.
Write a powershell script that creates a service from my executable pull_results.exe to run automatically for a group of users upon login.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # Define the service parameters $ServiceName = "PullResultsService" $DisplayName = "Pull Results Service" $Description = "This service automatically pulls results from a remote server upon user login." $ExecutablePath = "C:\path\to\pull_results.exe" # Create the service New-Service -Name $ServiceName -DisplayName $DisplayName -Description $Description -ExecutablePath $ExecutablePath -StartupType Automatic # Get the SID for the specified user group $GroupSID = (Get-WmiObject -Class Win32_Group -Filter "name='<group_name>'").SID # Add the user group to the service's ACL $Service = Get-Service $ServiceName $Service.AddAccessRule("Grant", "Start", "Allow", $GroupSID) # Start the service Start-Service $ServiceName # Ensure the service starts automatically at system boot Set-Service $ServiceName -StartupType Automatic |
Testing if the previous output contains the string pull_results.exe
: True
Testing if the previous output contains the string Set-Service
: True
Testing if the previous output contains the string sc.exe
: False
Testing if the previous output contains the string New-Service
: True
Write a powershell script that creates a service from my executable pull_results.exe to run automatically for a group of users upon login.
Write a powershell script that creates a service from my executable pull_results.exe to run automatically for a group of users upon login.
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 | # List of usernames for which to install the service $Users = "username1", "username2", "username3" # Executable path of the service $ExePath = "C:\Path\To\pull_results.exe" # Display name of the service $ServiceName = "PullResultsService" # Description of the service $ServiceDescription = "Collects results automatically" # Path to the service installation script $InstallScript = "C:\Path\To\InstallService.ps1" foreach ($User in $Users) { # Create a new session for each user $Session = New-PSSession -ComputerName localhost -Credential $User # Copy the installation script to the user's profile Invoke-Command -Session $Session -ScriptBlock { Copy-Item -Path $InstallScript -Destination "C:\Users\$($env:USERNAME)\Desktop\" } # Execute the installation script within the user's session Invoke-Command -Session $Session -ScriptBlock { & "C:\Users\$($env:USERNAME)\Desktop\InstallService.ps1" -ExePath "$ExePath" -ServiceName "$ServiceName" -Description "$ServiceDescription" } # Close the session Remove-PSSession -Session $Session } |
1 2 3 4 5 6 7 8 9 10 11 | param( [string]$ExePath, [string]$ServiceName, [string]$Description ) # Create the service using sc.exe sc create $ServiceName displayname= "$Description" binpath= "$ExePath" # Set the service to start automatically sc config $ServiceName start= auto |
Testing if the previous output contains the string pull_results.exe
: True
Testing if the previous output contains the string Set-Service
: False
Testing if the previous output contains the string sc.exe
: True
Testing if the previous output contains the string New-Service
: False