Command Line Cheat Sheet

Besides the graphical interface, Login AM also provides PoSh support for both the client and the admin commands, in order to work with the software.

Client commands

These commands can be run on a machine that is initialized with Login AM. In other words the client commands will work in the computers which are defined in a collection. You can either logon to a remote computer desktop, open the PowerShell console and start the AM client command-lets or directly open the remote PowerShell console from the Login AM User Interface.

Login AM Command Line Cheat Sheet 01.png

 

Initializing a computer. This script will initialize the computer in order to become a member of the Login AM configuration. The script will install the Login AM software and its current configuration to the local drive of the machine and a reboot will be invoked.

\\Server\AM$\(environmentID)\Initialize.ps1 

Initializing a computer and suppressing the reboot:

\\Server\AM$\(environmentID)\Initialize.ps1 -NoReboot 

While the machine has been initialized with Login AM the AM-client executes the AM command-lets

Note: This module needs to be imported in order to use the AM Client command-lets.

Importing the AM-client PoSh module:

Import-Module amclient 

Update the AM cache folder on the local machine:

Update-AMCache 

Update the AM cache folder, enable deployment, run startup and abort the pending reboots:

Update-AMCache; Enable-AMMaintenance; Invoke-AMEvent -Name Startup; shutdown -a 

Perform a maintenance reboot (will process deployment after reboot):

Invoke-AMEvent -name Reboot 

Perform a regular reboot (will not process deployment after reboot):

Restart-AMComputer 

The next commands are only available from version 1.2.33 and higher

Update the cache, enable deployment and run startup for a single package:

Update-AMCache; Enable-AMMaintenance; Invoke-AMPackage -Name "Name of package" -EventName "Startup" 

Update the cache, enable deployment and run deployment plugin for a single package:

Update-AMCache; Enable-AMMaintenance; Invoke-AMPackagePlugin -Name "Name of package" -PluginName "Deployment"

Admin Commands

These commands can be run in the Admin module of Login AM, which is running on the Login AM Server. To open the Admin module, either launch it via the Environment Manager (click on Admin API button) or load the module in PowerShell:

Login AM Command Line Cheat Sheet 02.png

Alternatively, you can import the Admin module from a plain PowerShell interface (without using the depicted Admin API button). For this, you need to gather the environment ID from the Environment Manager.

Login AM Command Line Cheat Sheet 03.png

 

Creating a package category, package and publish shortcut;

Please insert the correct <GUID> as the $EnvironmentID variable, as displayed in this example 8008389f-95ef-4865-993a-5f16c7b70837:

$PackageName = "A name of Package"
$PackageCat = "A name of Category"

$EnvironmentID = "8008389f-95ef-4865-993a-5f16c7b70837"

Import-Module "\\localhost\am`$\$EnvironmentID\bin\modules\admin\Automation Machine.psm1" -ArgumentList $EnvironmentID

#Refreshing the data for the Admin API:

$AMEnvironment = $AMDataManager.ReadEnvironment($AMEnvironment.Id,$true)

#Creating a new Package:
New-AMPackageCategory -Name $PackageCat

#Creating a new Package in that category
New-AMPackage -Name $PackageName -PackageCategory $PackageCat

# Add a new Action Set to a Package. You can alter the names defined in the variables to you own liking:

$Pkg = Get-AMPackage -Name $PackageName
$Plugin = Get-AMPlugin -Name "Shortcuts"
$ActionSet = New-Object AutomationMachine.Data.ActionSet
$ActionSet.Id = [guid]::NewGuid()
$ActionSet.PluginId = $Plugin.Id

# Set the name for the Action Set
$ActionSet.Name = "A Name for the ActionSet"

$ActionSet.Enabled = $true 
Read-AMActionItems $Pkg 
$ActionSet.OrderNumber = ($Pkg.ActionSets | ? {$_.pluginID -eq $Plugin.Id} | sort -property OrderNumber | Select -Last 1).OrderNumber + 1 
$Pkg.ActionSets.Add($ActionSet)  

# Save the Action Set to the Package:

Edit-AMPackage -Package $Pkg

# Add an Action Item to an Action Set in a Package:
# Get the package object
$Pkg = Get-AMPackage –Name $PackageName

# Get the ActionItem template
$AITemplate = Get-AMActionItemTemplate –Name "Create Shortcut"

# Create an actionitem instance for the package
$AI = $AITemplate.CreateInstance($Pkg.Id)

# Set the name for the Action Item
$Name = $AI.Variables | ? {$_.Name –eq "Name"}
$Name.Value = "ActionItem Name"

# Set the description
$Desc = $AI.Variables | ? {$_.Name -eq "Description"}
$Desc.Value = "A description"

# Set the target
$Target = $AI.Variables | ? {$_.Name –eq "Target" }
$Target.Value.Path = "C:\Windows\System32\notepad.exe"

# Set the working dir
$WorkDir= $AI.Variables | ? {$_.Name –eq "Working Directory" }

# note: using <Userprofile> will end up in the application as %Userprofile%
# To escape env vars use the < > signs
$WorkDir.Value.Path = "<Userprofile>"

# Set the arguments
$Arguments = $AI.Variables | ? {$_.Name –eq "Arguments" }
$Arguments.Value = "-A:yes"

# publish as remoteapp
$RemoteApp = $AI.Variables | ? {$_.Name –eq “Publish in RDS/XenApp/View” }
$RemoteApp.Value = $true

# Etc. continue for the other variables you can set
# Re-read the Action Sets/ Action Items for the package, so we are sure that changes made through the UI are also available
Read-AMActionItems $Pkg

# Assign the Action Item instance to an Action Set 
$ActionSet = $Pkg.ActionSets | ? {$_.Name –eq “A Name for the ActionSet”}
$AI.ActionSetId = $ActionSet.Id
$AI.OrderNumber = ($ActionSet.ActionItems | sort -property OrderNumber | Select -Last 1).OrderNumber + 1

# Finally save the Action Item to the Package
Set-AMActionItem –Component $Pkg –ActionItem $AI

Enable a Plugin for a Collection;

$Plugin = Get-AMPlugin -Name "Deployment"
$Collection = Get-AMCollection -Name "My Collection"
$am_col_enabled = Get-AMVariable -Name am_col_plugin_enabled -ParentId $Plugin.Id
Set-AMVariableOverride -Element $Collection -Variable $am_col_enabled -Value $true 

Enable a Plugin for a Package:

$Plugin = Get-AMPlugin -Name "Deployment"
$Pkg = Get-AMPackage -Name "My Package"
$am_pkg_plugin_enabled = Get-AMVariable -Name am_pkg_plugin_enabled -ParentId $Plugin.Id
Set-AMVariableOverride -Element $Pkg -Variable $am_pkg_plugin_enabled -Value $true 

Setting an override on a Global variable for a Package on a Collection level:

$Collection = Get-AMCollection -Name "My Collection"
$Pkg = Get-AMPackage -Name "My Package"
$Variable = Get-AMVariable -Name "var_name" -ComponentId $Package.Id
Set-AMVariableOverride -Element $Collection -Variable $Variable -Value "New value" 

Setting an override on the Plugin setting on a Collection level:

$Plugin = Get-AMPlugin -Name "Deployment"
$Collection = Get-AMCollection -Name "My Collection"
$Variable = Get-AMVariable -Name "var_name" -ParentId $Plugin.Id
Set-AMVariableOverride -Element $Collection -Variable $Variable -Value "New value"