Archive for the ‘PowerShell’ Category

PowerShell – Check if “SMS Agent Host” is Running and Start if Not

February 1, 2010 Leave a comment
# PowerShell script
# Josh Mueller – 2010
# Script to check whether the "SMS Agent Host" is running
# The script will start the service if it is not running
$sName = "SMS Agent Host"
$service = get-service -display $sName -ErrorAction SilentlyContinue
$startService = Start-Service $sname
if ($service.Status -eq "Running")
 { $sName + " is Running" }
else {$startService}
Categories: PowerShell

PowerShell – Start “SMS Agent Host” Service

February 1, 2010 Leave a comment
To start the "SMS Agent Host" service create a file called "ServiceStart.ps1" (or whatever you would like it to be) and copy the following into the file.
Start-Service "SMS AGENT HOST"
This should start the service.  You can manually stop it and then run this to test it.
Categories: PowerShell

PowerShell – Check the State of the “SMS Agent Host” Service

February 1, 2010 Leave a comment
Tio check the state of the "SMS Agent Host" service on the local device create a file named "Services.ps1" (or whatever you would like to call it).  Copy the following into the file:
get-service -display "SMS Agent Host"
Run the script and you should see output like below…
Status    Name                  DisplayName
——        —-                      ———–
Running  CcmExec            SMS Agent Host
Categories: PowerShell

PowerShell – ExecutionPolicy

February 1, 2010 Leave a comment
When you first try to use PowerShell on a device you may get the following error:
  • test.ps1 "cannot be loaded because the execution of scripts is disabled…"
To change this behavior you need to understand the "ExecutionPolicy".  The execution policy determines how, or if, PowerShell runs scripts.  Bty default PowerShell is set to "Restricted".  This means all scripts, even those you wrote yourself, are restricted.  To see the policy level you currently have run "Get-ExecutionPolicy".  To configure PowerShell to run – without question – any scripts that you write yourself, but to run scripts downloaded from the Internet only if those scripts have been signed by a trusted publisher do the following:
  • Set-ExecutionPolicy RemoteSigned
Categories: PowerShell
%d bloggers like this: