SDK Resources > Redirection Library > Redirection Library API > Sample Using the vPro Module
CollapseAll image

Sample Using the vPro Module

The following PowerShell code snippets demonstrate how to use the redirection library API. The snippets, like other PowerShell snippets in the SDK, depend on the Intel vPro Scripting Library. The redirection library DLL must be in the same directory as the snippet.

Snippet Demonstrating General Library Settings and Client Setup

You can execute this snippet by inserting it into the execution template found here.

  

$libSettingsFile =# Path of the Redirection library ini file (MC.ini)

$imrLib = New-Object Intel.Management.Redirection.MediaRedirection

 

# Initialize the Intel Media Redirection Library.

[Intel.Management.Redirection.IMRVersion]$imrVersion = New-Object Intel.Management.Redirection.IMRVersion

$imrResult =$imrLib.Init([ref]$imrVersion,$libSettingsFile)

 

# Define a redirection client based on the WsmanConnection Address

$imrClient =$imrLib.GetClientInfo($wsmanConnectionObject.Address)

 

# Add the redirection client to the Library (Library returns clientID).

$clientId =[System.UInt32]::MaxValue

$imrResult =$imrLib.AddClient($imrClient,[ref]$clientId)

 

Snippet Demonstrating Initiating a Storage Redirection Session

You can execute this snippet by inserting it into the execution template found here.

  

$floppyFile =# Path of the floppy file

$cdFile =# Path of the CD file.

 

# Create redirection session parameters (e.g. user name and password) based on the Wsman Connection.

$iderParams =$imrLib.CreateSessionParams($wsmanConnectionObject.Username,$wsmanConnectionObject.Password)

 

# Open an IDER session.

$imrResult =$imrLib.IDEROpenTCPSession(0,$iderParams,$imrLib.GetDefaultIDERTout(),$floppyFile,$cdFile)

 

# Params for setting device state.

$iderDeviceResult = New-Object Intel.Management.Redirection.IDERDeviceResult

$iderDeviceCmd = New-Object Intel.Management.Redirection.IDERDeviceCmd

 

$iderDeviceCmd.pri_op =[Intel.Management.Redirection.SetOperation]::Enable

$iderDeviceCmd.pri_timing =[Intel.Management.Redirection.SetOption]::Immediately

 

# Enable the ider device for immediate use by setting the device state.

$imrResult =$imrLib.IDERSetDeviceState($clientId,$iderDeviceCmd,[ref]$iderDeviceResult)

 

# Get statistics.

$iderStatistics = New-Object Intel.Management.Redirection.IDERStatistics

$imrResult =$imrLib.IDERGetSessionStatistics($clientId,[ref]$iderStatistics)

 

# Close the session.

$imrResult =$imrLib.IDERCloseSession($clientId)

 

Snippet Demonstrating Initating an SOL Session

You can execute this snippet by inserting it into the execution template found here.

  

# Create redirection session parameters (e.g. user name and password) based on the Wsman Connection.

$iderParams =$imrLib.CreateSessionParams($wsmanConnectionObject.Username,$wsmanConnectionObject.Password)

 

# Open SOL session.

$imrResult =$imrLib.SOLOpenTCPSession($clientId,$iderParams,$imrLib.GetDefaultSOLTout(),$imrLib.GetDefaultSOLParams())

 

# Recieve text by running the 'SOLRecieveText' function in loop while the session is open.

$recieveBuffer = New-Object Intel.Management.Redirection.ReceiveBuffer(20)

$imrResult =$imrLib.SOLRecieveText($clientId,$recieveBuffer)

$textRecieved =[Text.Encoding]::ASCII.GetString($recieveBuffer.Data)

 

# Send text.

$utf8 = new-Object System.Text.utf8encoding

$byteArray = New-Object byte[] 12

$textToSend ="text to send"

$utf8.GetBytes($textToSend, 0,$textToSend.Length,$byteArray, 0)

$imrResult =$imrLib.SOLSendText($clientId,$byteArray,$byteArray.Length)

 

# Close the session.

$imrResult =$imrLib.SOLCloseSession($clientId)

 

Snippet Demonstrating Shutting Down a Client and the Library

You can execute this snippet by inserting it into the execution template found here.

  

# Remove the client.

$iderParams =$imrLib.RemoveClient($clientId)

 

# Close the library.

$imrResult =$imrLib.Close()

 

Copyright © 2006-2022, Intel Corporation. All rights reserved.