src/utils.js
function checkExecutionPolicy () {
  return new Promise((resolve, reject) => {
    let output = []
    let child

    try {
      debug('Powershell: Attempting to spawn PowerShell child')
      child = spawn('powershell.exe', ['-NoProfile', '-NoLogo', 'Get-ExecutionPolicy'])
    } catch (error) {
      debug('Powershell: Could not spawn PowerShell child')
      reject(error)
    }

    child.stdout.on('data', (data) => {
      debug('PowerShell: Stdout received: ' + data.toString())
      output.push(data.toString())
    })

    child.stderr.on('data', (data) => {
      debug('PowerShell: Stderr received: ' + data.toString())
      output.push(data.toString())
    })

    child.on('exit', () => {
      const linesHit = output.filter((line) => line.includes('Unrestricted') || line.includes('RemoteSigned') || line.includes('Bypass'))
      const unrestricted = (linesHit.length > 0)

      if (!unrestricted) {
        debug('PowerShell: Resolving restricted (false)')
        resolve(false)
      } else {
        debug('PowerShell: Resolving unrestricted (true)')
        resolve(true)
      }
    })

    child.stdin.end()
  })
}
function checkExecutionPolicy () {
  return new Promise((resolve, reject) => {
    let output = []
    let child

    try {
      debug('Powershell: Attempting to spawn PowerShell child')
      child = spawn('powershell.exe', ['-NoProfile', '-NoLogo', 'Get-ExecutionPolicy'])
    } catch (error) {
      debug('Powershell: Could not spawn PowerShell child')
      reject(error)
    }

    child.stdout.on('data', (data) => {
      debug('PowerShell: Stdout received: ' + data.toString())
      output.push(data.toString())
    })

    child.stderr.on('data', (data) => {
      debug('PowerShell: Stderr received: ' + data.toString())
      output.push(data.toString())
    })

    child.on('exit', () => {
      const linesHit = output.filter((line) => line.includes('Unrestricted') || line.includes('RemoteSigned') || line.includes('Bypass'))
      const unrestricted = (linesHit.length > 0)

      if (!unrestricted) {
        debug('PowerShell: Resolving restricted (false)')
        resolve(false)
      } else {
        debug('PowerShell: Resolving unrestricted (true)')
        resolve(true)
      }
    })

    child.stdin.end()
  })
}
function checkExecutionPolicy ( ) { return new Promise ( ( resolve , reject ) => { let output = [ ] let child try { debug ( 'Powershell: Attempting to spawn PowerShell child' ) child = spawn ( 'powershell.exe' , [ '-NoProfile' , '-NoLogo' , 'Get-ExecutionPolicy' ] ) } catch ( error ) { debug ( 'Powershell: Could not spawn PowerShell child' ) reject ( error ) } child . stdout . on ( 'data' , ( data ) => { debug ( 'PowerShell: Stdout received: ' + data . toString ( ) ) output . push ( data . toString ( ) ) } ) child . stderr . on ( 'data' , ( data ) => { debug ( 'PowerShell: Stderr received: ' + data . toString ( ) ) output . push ( data . toString ( ) ) } ) child . on ( 'exit' , ( ) => { const linesHit = output . filter ( ( line ) => line . includes ( 'Unrestricted' ) || line . includes ( 'RemoteSigned' ) || line . includes ( 'Bypass' ) ) const unrestricted = ( linesHit . length > 0 ) if ( ! unrestricted ) { debug ( 'PowerShell: Resolving restricted (false)' ) resolve ( false ) } else { debug ( 'PowerShell: Resolving unrestricted (true)' ) resolve ( true ) } } ) child . stdin . end ( ) } ) }
Checks the current Windows PS1 execution policy. The upgrader requires an unrestricted policy.

@return {Promise.<boolean>} - True if unrestricted, false if it isn't
Checks the current Windows PS1 execution policy . The upgrader requires an unrestricted policy .