Snippet Demonstrating General Library Settings and Client Setup
$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 Initating an SOL Session
# 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)
沒有留言:
張貼留言