Powershell cmdlets: running a script remotely
Posted: Fri Jan 11, 2019 2:35 pm
Hi there,
Just wanted to ask if it is somehow possible to use StarWindX cmdlets while running a PowerShell script on a remote computer. Here is my code:
Here is the output:
I am able to use StarWindX cmdlets locally and fail to understand what I miss when using them remotely. On both remote and local machines, Powershell 4 is installed, and STA mode is the default. I even tried to use -sta in the command line (powershell -sta -file test.ps1 avo-vtl), but it didn't help.
Any chances to make it work?
Thank you.
Just wanted to ask if it is somehow possible to use StarWindX cmdlets while running a PowerShell script on a remote computer. Here is my code:
Code: Select all
param (
$tapeLibMachine
)
$mycreds = ConvertTo-SecureString "MyPassword" -AsPlainText -Force | % {New-Object System.Management.Automation.PSCredential ("$tapeLibMachine\Administrator", $_)}
$scriptBlock = {
try {
Import-Module StarWindX
$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind
Enable-SWXLog
$server.Connect()
}
catch {
$errDescription = $Error[0].Exception.Message
"Error occured: $errDescription"
}
finally {
$server.Disconnect()
}
}
Invoke-Command -Computername $tapeLibMachine -Credential $mycreds -ScriptBlock $scriptBlock
Code: Select all
C:\Scripts\>powershell .\test.ps1 avo-vtl
StarWindX doesn't support current appartment. You need to run this script with -STA switch to use StarWindX.
At C:\Scripts\test.ps1:32 char:1
+ Invoke-Command -Computername $tapeLibMachine -Credential $mycreds -ScriptBlock $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (StarWindX doesn... use StarWindX.:String) [], RuntimeException
+ FullyQualifiedErrorId : StarWindX doesn't support current appartment. You need to run this script with -STA switch to use StarWindX.
Any chances to make it work?
Thank you.