Create script for Pipeline to install Windows Service

Hello Everyone,

I’m new to the community and with PS. I am looking to create a script that I could put into a pipeline to create a windows service. For example I was playing around with the print spooler to test my code, but not sure if Im setting up my script right and looking for some guidance or maybe I’m making it more complicated then I need to.

Any advice is welcome

Configuration Main
 {
   Import-DscResource –ModuleName 'PSDesiredStateConfiguration'

   Node ('localhost')
   {
     Script DeployWindowsService
     {
       GetScript = {
         @{
           Result = ""
         }
       }

       TestScript = {
         $false
       }

       SetScript = {
            
            $serviceName = "Spooler"
            $displayName = "Spooler Demonstration"
            # location where spooler resides - Test
            $sourceLocation = "C:\Program Files (x86)\*"
            $destinationLocation = "C:\Windows\System32\*"
            $binaryName = $destinationLocation + "spoolsv.exe"
            $serviceDef = Get-Service –Name $serviceName –ErrorAction SilentlyContinue

            If ($serviceDef -eq $null)
            {
                # first install – create directory
                New-Item $destinationLocation –ItemType directory 
                Copy-Item $sourceLocation $destinationLocation –Force
                New-Service –Name $serviceName –StartupType Automatic –DisplayName $displayName –BinaryPathName $binaryName
            }
            else
            {
                # has already been installed
                if($serviceDef.Status -eq "Running")
                {
                    Stop-Service –Name $serviceName
                }
                Copy-Item $sourceLocation $destinationLocation –Force
            }
            
            Start-Service –Name $serviceName
       }
     }
   }
 }

 Main