Skip to content

Instantly share code, notes, and snippets.

@junecastillote
Last active Feb 3, 2022
Embed
What would you like to do?
1E Autonomous Persona Tag
@result = Tagging.Delete(Name: "Persona", Scopable: true);
#Region Module Prep
## Import the PSTachyonToolkit module
Import-Module PSTachyonToolkit
## Connect to the Tachyon server
Set-TachyonServer '1E01.corp.1EDemoLab.com'
## Set the licensed instruction prefix
Set-TachyonInstructionPrefix '1E-Demo'
#EndRegion
#Region Get Distinct Process Count
## Define the past number of days to query
$numDays = 7
## Calculate the oldest activity date to query
$startDate = ((Get-Date).AddDays(-$numDays)).ToString('yyyy-MM-dd')
## Build the dynamic instruction
$dynamicSplat = @{
# Target only Windows devices
TargetScope = "ostype=Windows"
# Count process names SoftwareInteraction_Daily table that from the last $numDays
Query = "SELECT Count(ProcessName) AS ProcessCount FROM `$SoftwareInteraction_Daily WHERE DATETIME(TS, 'unixepoch') >= '$($startDate)'"
# Override the schema and return only the ProcessCount field as an integer
Schema = 'ProcessCount int32'
}
## Invoke the dynamic instruction
$result = Invoke-TachyonDynamic @dynamicSplat
# $result | Export-Clixml result.xml
# Remove-Variable result
# $result = Import-Clixml .\raw.xml
## Merge Fqdn and values and add the persona
$result.Keys |
ForEach-Object {
$result[$_] | Add-Member -MemberType NoteProperty -Name Fqdn -Value $_ -Force
$result[$_] | Add-Member -MemberType NoteProperty -Name Persona -Value $(
if ($result[$_].ProcessCount -in 1..3) { 'Knowledge Worker' }
if ($result[$_].ProcessCount -in 4..8) { 'Task Worker' }
if ($result[$_].ProcessCount -ge 9) { 'Power User' }
) -Force
}
## Convert result from Hashtable to custom object and group by persona
$result = $result.Values.ToArray() | Sort-Object ProcessCount
$result
#EndRegion
#Region Delete Persona Tag
## Delete 'Persona' tags from all devices matching the '1EDemoLab.com' domain
Invoke-TachyonDynamic -Scale .\ClearPersonaTag.scale -TargetScope '1EDemoLab.com'
#EndRegion
#Region Apply Persona Tag
## Set the dynamic scale file path
$scaleFile = '.\SetPersonaTag.scale'
## Group devices by Persona
$result | Group-Object Persona |
## Process each device persona group
ForEach-Object {
## Create the dynamic SCALE code file for the current device persona group
'@result = Tagging.Set(Name:"Persona",Value:"' + $_.Name + '",Scopable:true);' | Out-File $scaleFile -Force
## Invoke the dynamic SCALE instruction
Invoke-TachyonDynamic -Scale $scaleFile -TargetFqdns $_.Group.Fqdn
}
Get-TachyonDevice -Full | Format-Table Fqdn, CoverageTags, Tags
#EndRegion
#Region Create management groups
@('Knowledge Worker', 'Task Worker', 'Power User') |
ForEach-Object {
$persona = $PSItem
if ($fqdn = (Get-TachyonDevice -Full | Where-Object { $_.CoverageTags.Persona -eq $persona }).Fqdn) {
Set-TachyonSLADirectManagementGroup -Name $persona -FqdnList $fqdn
}
}
#EndRegion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment