# Administration Using PowerShell Scripts

## Import-Module AlembaUtils

<figure><img src="https://content.gitbook.com/content/6Ckybwmt0tmi7y8MgYX4/blobs/yorsvZWfUe1xExAZ6Meo/image.png" alt=""><figcaption></figcaption></figure>

## Use Get-Help ( PowerShell Feature) to display information about each function

An example: Changing and getting the value of Time Out

```powershell
get-help Set-ServiceManagerSystemProperty
```

In the received information, you find:&#x20;

{% code overflow="wrap" %}

```powershell
“Set-ServiceManagerSystemProperty -SystemNameproduction -Name TimeOut -Value 240” 
```

{% endcode %}

Change the value to the desired one and enter it as a new command:&#x20;

{% code overflow="wrap" %}

```powershell
Set-ServiceManagerSystemProperty -SystemName production -Name TimeOut -Value 300
```

{% endcode %}

To get the information about the new TimeOut Value: The Syntax section helps you go from:

{% code overflow="wrap" %}

```powershell
SYNTAX
    Set-ServiceManagerSystemProperty [[-Value] ,Object>] [[-Name] ,String.] [[-SystemName] ,String.] [,CommonParameters.]
    
```

{% endcode %}

To:

{% code overflow="wrap" %}

```powershell
Get- ServiceManagerSystemProperty –Name TimeOut –SystemName “production”
```

{% endcode %}

<figure><img src="https://content.gitbook.com/content/6Ckybwmt0tmi7y8MgYX4/blobs/9FBYNsTFVTZqV8pLqvgs/image.png" alt=""><figcaption></figcaption></figure>

## AlembaUtils Functions

### Get-ServiceManagerSystemAdminModule

```powershell
.SYNOPSIS
Get the admin module for a named ASM system

.DESCRIPTION
Get the admin module for a named ASM system

.PARAMETER SystemName
The name of the Service Manager system

.EXAMPLE
Get-ServiceManagerSystemAdminModule -SystemName production
```

### Get-ServiceManagerSystemNames

```powershell
.SYNOPSIS
Get a list of installed alemba systems

.DESCRIPTION
Get all local alemba system names as an array of strings

.EXAMPLE 
Get-ServiceManagerSystemNames

```

### Get-ServiceManagerSystemPath

{% code overflow="wrap" %}

```powershell
.SYNOPSIS
Get the install path for a named Service Manager System

.DESCRIPTION
Returns the path to the system folder for a named system

.PARAMETER SystemName
The name of the Service Manager system

.EXAMPLE 
Get-ServiceManagerSystemPath -SystemName production 

=> C:\alemba\Service Manager\web\systems\production\
```

{% endcode %}

### Get-ServiceManagerSystemProperty

{% code overflow="wrap" %}

```powershell
SYNOPSIS
Get the current value of a specified system property for a named Service Manager system

SYNTAX
Get-ServiceManagerSystemProperty [-SystemName] <Object> [-Name] <String> [<CommonParameters>]

DESCRIPTION
Returns the string value of the specified system property

REMARKS
To see the examples, type: "get-help Get-ServiceManagerSystemProperty -examples".
For more information, type: "get-help Get-ServiceManagerSystemProperty -detailed".
For technical information, type: "get-help Get-ServiceManagerSystemProperty -full".

COMMON PARAMETERS (you can press "TAB" to cycle through them in Powershell):
Timeout
TimeoutLite
DefaultDateFormat
CurrencySign
MMAURL
LicenceKey
EnableVirusCheck
EnableTracing
ConnectionString

```

{% endcode %}

### Get-ServiceManagerVersion

<pre class="language-powershell" data-overflow="wrap"><code class="lang-powershell">.SYNOPSIS
Get the version of Alemba Service Manager 
<strong>
</strong><strong>.DESCRIPTION
</strong>Returns a Version value representing the currently installed version of Alemba Service Manager

.EXAMPLE 
Get-ServiceManagerVersion =>
Major Minor Build Revision
----- ----- ----- -------- 
10     5     1     12345
</code></pre>

### Invoke-QueryParser

{% code overflow="wrap" %}

```powershell
.SYNOPSIS
Parse Queries for the named system

.DESCRIPTION
Executes the parse queries process for the named Alemba Service Manager system You must restart web and windows services after executing this function

.PARAMETER SystemName
The name of the Service Manager system

.EXAMPLE
Invoke-QueryParser -SystemName production
```

{% endcode %}

### Invoke-SQL

{% code overflow="wrap" %}

```powershell
.SYNOPSIS
Execute a sql query using the database for a Service Manager system

.DESCRIPTION
Execute a sql query using the database for a Service Manager system Does not return any results

.PARAMETER System
The name of the Service Manager system or a reference to the System Admin Module for the named system. For optimal performance, pass a reference to an existing instance of a System Admin Module when you plan to iteratively execute many sql queries 

.PARAMETER SQL
    The SQL query text. e.g. 
    select NAME from SU_CALL_PRIORITY where REF = @REF" 
    
.PARAMETER Parameters
Optional hashtable of SQL Query parameters. e.g. 

@{ REF = 1, NAME = "Priority 1" }

Types must conform to known SQL Server Data Types. These are usually [int32] and [s
tring] and in these cases the types are inferred

.EXAMPLE
Invoke-SQL -System production -SQL "select Name from SU_CALL_PRIORITY where REF = @REF" -Parameters @{ REF = 1; }

```

{% endcode %}

### Invoke SQLReader

{% code overflow="wrap" %}

```powershell
.SYNOPSIS
Execute a sql query using the database for a Service Manager system

.DESCRIPTION
Execute a sql query using the database for a Service Manager system Returns results as an array of hashtables. e.g. 

@(@{ REF = 1; NAME = "P1"; }; @{ REF = 2; NAME = "P2"}; )

.PARAMETER System
The name of the Service Manager system or a reference to the System Admin Module for the named system. For optimal performance, pass a reference to an existing instance of a System Admin Module when you plan to iteratively execute many sql queries

.PARAMETER SQL
    The SQL query text. e.g. 
    
    select NAME fromSU_CALL_PRIORITY where REF = @REF" 
    
.PARAMETER Parameters
Optional hashtable of SQL Query parameters. e.g. 
@{ REF = 1, NAME = "P1" }

Types must conform to known SQL Server Data Types. These are usually [int32] and [s
tring] and in these cases the types are inferred

.EXAMPLE
Invoke-SQLReader -System production -SQL "select Name from SU_CALL_PRIORITY where REF = @REF" -Parameters @{ REF = 1; }

```

{% endcode %}

### Invoke-SQLScript

{% code overflow="wrap" %}

```powershell
.SYNOPSIS
Execute a sql queries from a file using the database for a Service Manager system

.DESCRIPTION
Execute a sql queries from a file using the database for a Service Manager system Does not return any results
Use GO; on a new line to separate scripts within the file

.PARAMETER System
The name of the Service Manager system or a reference to the System Admin Module for the named system. For optimal performance, pass a reference to an existing instance of a System Admin Module when you plan to iteratively execute many sql queries 

.PARAMETER FileName
Path to a file containing SQL commands.
The path can be relative to the current working directory

.EXAMPLE
Invoke-SQLScript -System production -FileName ".\script.sql" 

```

{% endcode %}

### Set-ServiceManagerUserPassword

{% code overflow="wrap" %}

```powershell
.SYNOPSIS
Set a new password for an existing ASM user

.DESCRIPTION
Set a new password for an existing ASM user
Only applicable when using ASM Password authentication
This is intended to be used to securely restore admin access to a system when no ot her user can access ASM

.PARAMETER SystemName
The name of the Service Manager system

.PARAMETER Username
The username (USER_ID) of the ASM User Account

.PARAMETER Password
    The new password
    
.EXAMPLE
Set-ServiceManagerUserPassword -SystemName production -Username "admin.user" -
Password ********
```

{% endcode %}

### Set-ServiceManagerSystemProperty

{% code overflow="wrap" %}

```powershell
.SYNOPSIS
Set system properties for a Service Manager system

.DESCRIPTION
Execute a sql queries from a file using the database for a Service Manager system Does not return any results
Use GO; on a new line to separate scripts within the file

.PARAMETER SystemName
The name of the Service Manager system

.PARAMETER Name
    The name of the system property
    
.PARAMETER Value
The value of the system property

.EXAMPLE
Set-ServiceManagerSystemProperty -SystemName production -Name TimeOut -Value 240

.EXAMPLE
Set-ServiceManagerSystemProperty -SystemName production -Name CurrencySign -Value "£"
```

{% endcode %}

<figure><img src="https://content.gitbook.com/content/6Ckybwmt0tmi7y8MgYX4/blobs/MG0usgWjBLqw2WdoxMkX/image.png" alt=""><figcaption></figcaption></figure>

## Additional Information

[https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format- strings](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings)

<https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/connection-string-syntax>
