Powershell command not working when run by octopus deploy - powershell

I have several steps to figure out this problem and I do't know what else to do. My end goal is to check my "app.exe" file version. when I run it on server manually both script versions work. But when Octopus runs both versions fail with different errors
Version 1:
$file = "C:\Octopus\Applications\AppStartUp\38.2.19.0\app.exe"
$fileVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($file).FileVersion
I get the error:
return [System.Diagnostics.FileVersionInfo]::GetVersionInfo <<<< ($file). FileVersion
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : DotNetMethodException
Version 2:
$file = "C:\Octopus\Applications\AppStartUp\38.2.19.0\app.exe"
(Get-Command "$file").FileVersionInfo.Fileversion
Error Message
Export-ModuleMember : The Export-ModuleMember cmdlet can only be called from in side a module. At C:\Octopus\Applications\CSIS_DEV\ESG.CSIS.StartUp\38.2.19.0\deployment\clickOnceLib.ps1:35 char:20
+ Export-ModuleMember <<<< -function * -alias *
+ CategoryInfo : PermissionDenied: (:) [Export-ModuleMember], InvalidOperationException
+ FullyQualifiedErrorId : Modules_CanOnlyExecuteExportModuleMemberInsideAModule,Microsoft.PowerShell.Commands.ExportModuleMemberCommand
Get-Command : The term 'C:\Octopus\Applications\CSIS_DEV\ESG.CSIS.StartUp\38.2.19.0\ESG.CSIS.StartUp.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Octopus\Applications\CSIS_DEV\ESG.CSIS.StartUp\38.2.19.0\deployment\clickOnceLib.ps1:32 char:24
+ return (Get-Command <<<< "$file").FileVersionInfo.Fileversion
+ CategoryInfo : ObjectNotFound: (C:\Octopus\Appl...SIS.StartUp.exe:String) [Get-Command], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
Any Insite to these messages and why it happens only when running in octopus would be great.

It looks like your script can't access the file, or it doesn't exist. Check to make sure C:\Octopus\Applications\CSIS_DEV\ESG.CSIS.StartUp\38.2.19.0\ESG.CSIS.StartUp.exe exists and is accessible to the user the tentacle runs under (use windows effective permissions).
Also make sure it's there by the time the script runs, you haven't mentioned whether this is a seperate step, PreDeploy.ps1, Deploy.ps1 or PostDeploy.ps1 script

Related

Why won't it allow me to activate my venv?

I've researched a few things about opening a venv. I've come to realize I need the PowerShell to allow scripts and so I started this session with:
set-executionpolicy remotesigned
Then I went ahead and tried the following, but it is not going through.
P
S C:\Windows\system32\xxxxx> venv/bin/activate
venv/bin/activate : The term 'venv/bin/activate' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ venv/bin/activate
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (venv/bin/activate:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Windows\system32\xxxxx> source venv/bin/activate
source : The term 'source' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ source venv/bin/activate
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (source:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Any suggestions as how to move forward?
I had been following a tutorial and they used venv/bin/activate when it should be venv/Scripts/activate

MSI install powershell program but no modules available

I installed AutomatedLab.msi from here - https://github.com/AutomatedLab/AutomatedLab/releases
it installed without any errors but there doesn't appear to be any powershell modules available... or it doesn't seem to know where the modules are? Is there anything else that I can do...
PS C:\Users\Administrator\Downloads> Get-LabAvailableOperatingSystem -Path C:\LabSources
Get-LabAvailableOperatingSystem : The term 'Get-LabAvailableOperatingSystem' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-LabAvailableOperatingSystem -Path C:\LabSources
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-LabAvailableOperatingSystem:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Is there some special way I'm supposed to install msi executables? Ive tried 'start-process' I've tried "Install-Module MSI" I can't seem to get anything to work.
Any suggestions?

Getting cluster detail of Windows

Is there any other way to get Windows cluster details like cluster & machine info using PowerShell command?
I tried to use Get-Cluster command but it's not working throwing an error.
get-cluster : The term 'get-cluster' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ get-cluster
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (get-cluster:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Powershell not always running ScriptsToProcess on import

After using Install-Module to install powershell-yaml I had about a week of use before I came in one morning to it not loading YamlDotNet properly.
Now if I try to use ConvertFrom-Yaml before manually running Import-Module powershell-yaml I get the the following error:
PS C:\Users\user> "---" | ConvertFrom-Yaml
New-Object : Cannot find type [YamlDotNet.RepresentationModel.YamlStream]: verify that the assembly containing this type is loaded.
At C:\Program Files\WindowsPowerShell\Modules\powershell-yaml\0.3.1\powershell-yaml.psm1:24 char:23
+ ... $yamlStream = New-Object "YamlDotNet.RepresentationModel.YamlStream"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\powershell-yaml\0.3.1\powershell-yaml.psm1:25 char:9
+ $yamlStream.Load([System.IO.TextReader] $stringReader)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Previously (and on most systems) this worked fine. If I run a manual Import-Module before calling the function it works fine:
PS C:\Users\user> Import-Module powershell-yaml
PS C:\Users\user> "---" | ConvertFrom-Yaml
PS C:\Users\user>
Both my and a coworker's machines started this behavior at about the same time. This morning my system started working properly again, but his is still exhibiting the behavior. We haven't been able to duplicate it on other machines.
I've narrowed it down to a script referenced in Powershell-Yaml manifest's ScriptsToProcess not being called during autoload, but runs fine during a manual Import-Module. On working machines the script in ScriptsToProcess is run in both cases. As a workaround we can force a module load by putting an Import-Module in our profile, ideally we'd like to find a root cause.
Import-Module -Verbose doesn't help, because calling Import-Module first always works.

Unable to Use Windows Update COM object in RemotePS sessions

Im trying to change the windows update settings in a remote server using powershell, but when i run the below commands it gives me an error.
PS C:\Windows\system32> Enter-PSSession opalisbinary
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings.NotificationLevel=2
Property 'NotificationLevel' cannot be found on this object; make sure it exists and is settable.
At line:1 char:14
+ $AUSettings. <<<< NotificationLevel=2
+ CategoryInfo : InvalidOperation: (NotificationLevel:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings.IncludeRecommendedUpdates=$true
Property 'IncludeRecommendedUpdates' cannot be found on this object; make sure it exists and is settable.
At line:1 char:14
+ $AUSettings. <<<< IncludeRecommendedUpdates=$true
+ CategoryInfo : InvalidOperation: (IncludeRecommendedUpdates:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings.Save()
You cannot call a method on a null-valued expression.
At line:1 char:18
+ $AUSettings.Save <<<< ()
+ CategoryInfo : InvalidOperation: (Save:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Although when i run it locally on the server it works fine...
Could anyone please help me.
Does it work when you connect via Remote desktop and run the commands? It also depends on the bittnes. I don't know the Microsoft.Update.AutoUpdate, so I'm just guessing, but - is it available for x64 version of PowerShell? In other words if you run it locally in x64 version and x86, do you see the errors?
I am sorry, I could not find a real answer. What I found is this link which states that remote PS sessions can be used with SCCM 2012, but they could not with SCCM 2007.
This does not help you, but it seems that not all COM objects are compatible with remote PS sessions.