PowerShell Interface
The LOGINventory PowerShell add-on provides you with a full script interface for Windows PowerShell 4.0 or later. This makes it possible to specifically access all data in the LOGINventory database and process and prepare them as required.
The add-on consists of a PowerShell Provider to move in the tree structure of LOGINventory and several CommandLets (also: CmdLets), which cover certain functions (reports, mail, setting own properties, etc.) and are continuously extended.
In addition to the special LOGINventory CmdLets, all standard CmdLets can also be used, such as Export-Csv.
Example:
PS LI:\> cd '.\IT Inventory\Assets'
PS LI:\IT Inventory\Assets> Get-LiData | Export-Csv c:\temp\export.txt
System Requirements
Windows PowerShell version 3.0 (already installed on Windows 8 or later and Windows Server 2012 or later) or newer must be installed. The default setting of Windows PowerShell is to prevent the execution of scripts (ExecutionPolicy = Restricted)! You must first enable this function, e.g. via an administrative PowerShell:
C:\> Powershell -command Set-ExecutionPolicy ByPass -scope LocalMachine
Call PowerShell
The LOGINventory PowerShell can be called either via the ribbon menu under Extras or via the supplied program PSC.exe, optionally with specification of the ExecutionPolicy, a script file or other parameters, e.g..:
C:\> "%ProgramFiles%\LOGIN\LOGINventory8\PSC.exe" -ExecutionPolicy bypass -file "C:\myscript.ps1" [parameter]
Scripts can be executed within the LOGINventory PowerShell without restrictions.
Calling the LOGINventory PowerShell from the Windows PowerShell
To call the LOGINventory Powershell from the Windows Powershell, it must first be initialized.
The following script is installed by default and can be found under the name InitOtherClients.ps1
from the 'LOGINventory PowerShell Samples' folder in the Start menu. Please note that also the commented out commands at the beginning of the script must be executed according to your environment!
# Init Loginventory environment for other clients like powershell_ise.exe ...
# First, you have to install LOGINventory Powershell compononets by using installutil in an administrative command promptfor the 64 bit Version of the Powershell:
# installutil /i [LoginventoryBinaryPath]\Login.Ventory.PowerShell.CmdLets.dll
# installutil /i [LoginventoryBinaryPath]\Login.Ventory.PowerShell.Provider.dll
# For example:
# C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /i "C:\Program Files\LOGIN\LOGINventory8\Login.Ventory.PowerShell.CmdLets.dll"
# C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /i "C:\Program Files\LOGIN\LOGINventory8\Login.Ventory.PowerShell.Provider.dll"
# If you experience problems, try also the 32 bit version:
# C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /i "C:\Program Files\LOGIN\LOGINventory8\Login.Ventory.PowerShell.CmdLets.dll"
# C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /i "C:\Program Files\LOGIN\LOGINventory8\Login.Ventory.PowerShell.Provider.dll"
Add-PSSnapin loginventory
Add-PSSnapin loginventorycmdlets
# Set culture to english (no data translation)
[System.Threading.Thread]::CurrentThread.CurrentUICulture = "en-US"
[System.AppDomain]::CurrentDomain.SetPrincipalPolicy([System.Security.Principal.PrincipalPolicy]::WindowsPrincipal)
#[System.AppDomain]::CurrentDomain.SetData("APPBASE", "[LoginventoryBinaryPath]"), for example:
[System.AppDomain]::CurrentDomain.SetData("APPBASE", "C:\Program Files\LOGIN\LOGINventory8")
New-PSDrive -Scope global -Name LI -PSProvider LOGINventory -Root ""
cd LI:
# have fun :)
Now you can navigate in the tree structure using the commands explained below.
Tip
If you want to access the LOGINventory Powershell in Tasks, then the corresponding parts of the script have to be taken from the script as well.
PowerShell Samples
With the installation of LOGINventory also some sample scripts are delivered. The LOGINventory PowerShell Samples shortcut (found in the Start menu) gives you an overview of the available examples in an Explorer window.
To start one of the example scripts, it is sufficient to:
- open the PowerShell LOGINventory8 console,
- drag & drop a .ps1 file of the script into the opened LOGINventory PowerShell window,
- to press the ENTER button.
The scripts may have to be adapted to your environment:
- You may not be able to start the sample scripts because you do not have permission to start scripts from the program directory. Therefore, copy the entire samples directory to a local path (e.g. c:\Scripts).
- During the update to a new LOGINventory version, the supplied PowerShell samples are overwritten in the installation directory, which means that changes and additions by the user are lost. For this reason, we also recommend that you do not revise the samples in the original directory!
- In the scripts, filters are set to asset names ('Device.Name' -like "DE*"), which you have to adjust accordingly.
The example scripts are structured according to the following scheme:
1 # Call these scripts:
2 # [ProgDir]\PSC.exe -file "path\scriptname.ps1" [parameter]
3 # Save current path, to restore at the end ...
4 $savePath=$PWD
5 cd "LI:\Software Licenses"
6 Get-LiData | Where {$_.'License.Required' -gt $_.'License.Available'}
7 cd $savePath
- First, the current path is saved (line 4).
- Then change to the desired evaluation path (line 5).
- Then the desired CmdLets are executed
- Finally the original path restored (line 7)
The Concept of the LOGINventory PowerShell Provider
Navigation through the LOGINventory tree structure is done with the commands CD
(or: Set-Location
) and DIR
(or: Get-LiData
)
known from the DOS-Box. The names of the nodes in the tree are not localized in the PowerShell, so they always correspond to the English name; exception: "License Management" means "Software Licenses" in the PowerShell. When navigating with CD
, auto-completion with the TAB key also works. Thus the directory names do not need to be written out completely.
Important
The result list of each node can be retrieved with the CmdLet Get-LiData
.
Available Commands
Besides the general Windows PowerShell CmdLets (https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/?view=powershell-3.0) there are LOGINventory specific commands. In general, the output of the command is filtered via a where-CmdLet
and used as an input parameter for other CmdLets.
Retrieve Data
Syntax: Get-LiData -View <String>
Returns the information of the detail view for the selected node in the LOGINventory tree, for the standard view.
Parameters | Possible values | Required? |
---|---|---|
-View <String> |
ChangeLog, ComputerAccounts, UserAccounts | no |
Example: Get-LiData -view ComputerAccounts
.
Archive Devices
Syntax: Disable-LiAsset [-AssetName 'String'] [-InputObj 'PSObject[]']
Archives the corresponding assets.
Parameter | Explanation | Required? |
---|---|---|
-InputObject 'Object' | List of devices | yes |
Example (pipe): Get-LiData | ? name -like DES* | Disable-LiAsset
Example (direct): Disable-LiAsset -AssetName MyDevice
Reactivate Devices
Syntax: Enable-LiAsset [-AssetName 'String'] [-InputObj 'PSObject[]']
Reactivates selected assets from the archive.
Parameters as for archiving.
Example (pipe): Get-LiData | ? name -like DES* | Enable-LiAsset
Example (direct): Enable-LiAsset -AssetName MyDevice
Delete Devices
Syntax: Remove-LiAsset [-AssetName 'String'] [-InputObj 'PSObject[]']
Deletes the selected assets permanently.
Parameters as for archiving
Example (pipe): Get-LiData | ? name -like DES* | Remove-LiAsset
Example (direct): Remove-LiAsset -AssetName MyDevice
Setting Custom Properties
Syntax: Set-LiCustomProperty -Name 'String' -Value 'String|DateTime|Int64'[-AssetName 'String'] [-InputObj 'PSObject']
Assigns a Custom property to the specified asset.
Parameter | Explanation | Required? |
---|---|---|
-Name <String> |
Name of the (new) property, no special characters or spaces | yes |
-Value 'String/DateTime/Int64' |
Value of the property to be set | yes |
-AssetName <String> |
Name of the device to which the property is to be assigned | yes |
Info
If you want to assign a value via the Powershell to a custom property that only offers a certain set of choices (=Enum), such as "FunctionalRole", the parameter Value
must use the following syntax: -Value [Login.Ventory.Data.Model.FunctionalRole]::Testing)
(if the role "Testing" is to be assigned)
By the way, the possible values can be queried with the command [Enum]::GetValues([Login.Ventory.Data.Model.FunctionalRole])
.
Examples:
Set-LiCustomProperty -Name "RoomNr" -Value "R 317" -AssetName "Server01"
Set-LiCustomProperty -Name "InstDatum" -Value 15.02.2013 -AssetName "Server01"
Set-LiCustomProperty -Name "FunctionalRole" -value ([Login.Ventory.Data.Model.FunctionalRole]::Production) -AssetName "Server01"
Get-LiData | ? name –like DES* | Set-LiCustomProperty –Name "PriceInEuro” –Value 799
Query Custom Properties
Syntax: Get-LiCustomProperty -Name 'String' [-AssetName 'String'] [-InputObj 'PSObject[]']
Reads the value of a custom property.
Parameter | Explanation | Required? |
---|---|---|
-Name <String> |
Name of the property to be read out | yes |
-AssetName <String> |
Name of the device from which the property is to be read | yes |
Examples:
Get-LiCustomProperty -Name "RoomNr" -AssetName "Server01"
Get-LiData| ? name -eq DESTINY | Get-LiCustomProperty -Name "InstDatum"
Emptying Custom Properties
Syntax: Remove-LiCustomProperty -Name 'String'
Clears all entries in the Custom Property in the entire database.
Parameter | Explanation | Required? |
---|---|---|
-Name <String> |
Name of the property to be emptied | yes |
Example: Remove-LiCustomProperty -Name "RoomNr"
Deleting Entries from "Failed Inventory"
Syntax: Remove-LiInventoryInfo
Deletes entries from the "Failed Inventory" query.
Example:
CD "\Failed Inventory"
get-lidata | ? targetname -like CL* | Remove-LiInventoryInfo
Add Journal Entry
Syntax:
Adds a journal entry with the specified values.
Example:
get-lidata | ? name -like Des* | Add-LiJournalEntry -Subject Repair -Start 15.11.2018 -End 18.11.2018 -Body "CPU has been replaced" -End 18.11.2018
Combination of Commands
As shown in the examples above, individual CmdLets can be combined using the Pipe |. The output of the command to the left of | is used as input parameter for the command to the right.
Example task
"In all assets whose name begins with "DES", add an Own property "PriceInEuroCent" with the price of the device:
Solution:
PS LI:\> cd '.\IT Inventory\Assets'
PS LI:\IT Inventory\Assets> Get-LiData | where {$_.'name' –like "DES*"} | Set-LiCustomProperty –Name "PreisInEuroCent" –Value 78999