none
Passing variable from PS to Batch file RRS feed

  • Question

  • I'm trying to get a script setup to remotely enable the WinRM service and then get PowerShell setup so it'll accept remote connections. I'm using PSExec for that second part, but I can't get it to work in PowerShell so I thought that maybe I could do the first part with PowerShell and then let a batch program take care of the rest with PSExec. Here's what I have so far:

    Param(
          [Parameter(Mandatory=$True)]
          [String]
          $ComputerName
          )
    
    Get-Service "WinRM" -ComputerName $ComputerName | Set-Service -StartupType Automatic | Start-Service
    
    Start-Process "C:\Users\alex.franco\Documents\Batch Programs\PSRemoting.bat"

    And the contents of the PSRemoting.bat:

    C:\PSTools\PSExec.exe \\$ComputerName -h -d powershell.exe "enable-psremoting -force"
    pause

    The issue is pulling the $ComputerName variable from PowerShell and using it in the batch file. Any suggestions how I could do this?

    Thanks!

    Friday, August 14, 2015 7:13 PM

Answers

All replies