SCRIPT: Performing StifleR Admin functions with PowerShell | 2pint Knowledge Base

SCRIPT: Performing StifleR Admin functions with PowerShell

<#
This contains examples of PS that you can execute to perform actions on the StifleR Server
such as force the clients to update rules or run a scripts etc
#>
####Update Rules - for a specific subnet, machine, or all - Replace the xxxxxxxxx with a Network ID, Individual ClientID or just specify ALL for all clients
#This will trigger a message form the server to all clients to get the latest StifleRRules.xml - not that this only happens when the client is next actively downloading
Invoke-WmiMethod -Namespace root\StifleR -Path StifleREngine.Id=1 -Name UpdateRules -ArgumentList  "http://192.168.1.100/StiflerRules/StifleRulez.xml", "All",1
#END Update Rules
### Update Rules on a single computer ###
### Prompts the user for a computer name and then sends an update rules instruction to that client
$Cname = Read-Host -Prompt 'Input the Computer Name to Update StifleR Rules'
$c = gwmi -namespace root\StifleR -Query "Select * From Clients where computername = '$Cname'"
$id = $c.connectionid
Invoke-WmiMethod -Namespace root\StifleR -Path StifleREngine.Id=1 -Name UpdateRules -ArgumentList  "http://CHSCCM01W.somerset.gov.uk/StiflerRules/StifleRulez.xml", "$id",0
### END Update Rules on a single computer ###
### Increase the Target Bandwidth by XX% across all subnets. You can use this along with Task Scheduler to raise/lower bandwidth limits at certain times
#REsume All Downloads
Invoke-WmiMethod -Namespace root\StifleR -Path StifleREngine.Id=1 -Name ModifyJobs -ArgumentList "Resume", True, "*", 0, "All"

#Suspend all downloads - for a specific subnet or '*' for All
Invoke-WmiMethod -Namespace root\StifleR -Path StifleREngine.Id=1 -Name ModifyJobs -ArgumentList "Suspend", True, "*", 0, "All"
 
### QUick n Dirty Locationdata cleanup ###
# This will stop the stifler server service, remove the specifice subnets and restart the service #
#makes a backup copy first in case you need to roll back #
#Stop the StifleR Server  Service
Stop-Service "StifleRServer" -force
$ts = $(get-date -f MMddyyyy)+$(get-date -f HHmmss)
###Location Data XML path
$locdatapath = "$ENV:PROGRAMDATA\2Pint Software\StifleR\Server"
###Take a backup
If (!(Test-Path $locdatapath\Backup)){New-Item -ItemType Directory -Force -Path $locdatapath\Backup}
If (Test-Path $locdatapath\locationdata.xml) {copy-item $locdatapath\locationdata.xml $locdatapath\Backup\locationdata.$ts.bak -Force}
### Remove all the Unwanted Locations - then save ###
$xml = [xml](Get-Content $locdatapath\locationdata.xml)
$RemoveLoc = $xml.Root.Location | Where-Object {($_.Subnet -eq "192.168.1.0") -or ($_.Subnet -eq "0.0.0.0")}
foreach ($loc in $RemoveLoc){
$xml.Root.RemoveChild($Loc)}
$xml.save("$locdatapath\locationdata.xml")
Start-Service StifleRServer
### QUick n Dirty Locationdata cleanup ###
 
$alllocs = @(gwmi -namespace root\StifleR -Query "Select * from Subnets where TargetBandwidth > 500")#where TargetBandwidth > 4090")

foreach ($loc in $alllocs)
{
    $NewTargetBandwidth = $loc.TargetBandwidth * (1 + ($BWVariation/100))
#Set the new subnet speed
    swmi -path $loc.path -Arguments @{TargetBandwidth = $NewTargetBandwidth }
}