Search code examples
powershellservicednshostname

Powershell How To Input Computername To Check


I want to check the services for a computer in Powershell. I've made the 'check services' part of the script. I cannot add the additional part to input which server in the domain to check. My script only checks my local computer. I need to be prompted to input which server to check in the LAN.

bot$Servicename = "Security Center"

$ServiceName = "Security Center"
function FuncCheckService{
param($ServiceName)}
$arrService = Get-Service -Name $ServiceName
if ($arrService.Status -ne "Running"){
Start-Service $ServiceName
Write-Host "Starting " $ServiceName " service" }
FuncCheckService -ServiceName "security center"

Solution

  • You can use

    $Server = Read-Host -Prompt 'Input your server name'
    Get-Service -Name $ServiceName -computername $Server
    

    Reference