So the folder you mentioned seems not to exist. I did find the modules in:
~/.local/share/powershell/Modules
This is what I'm running into now:
Oct 20 23:23:26 cec-esxi-mgmt pwsh[6701]: Import-Module : The specified module 'VMware.VimAutomation.sdk' was not loaded because no valid module file was found in any module directory.
Oct 20 23:23:26 cec-esxi-mgmt pwsh[6701]: At line:2 char:1
Oct 20 23:23:26 cec-esxi-mgmt pwsh[6701]: + Import-Module -Name 'VMware.VimAutomation.sdk'
Oct 20 23:23:26 cec-esxi-mgmt pwsh[6701]: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Oct 20 23:23:26 cec-esxi-mgmt pwsh[6701]: + CategoryInfo : ResourceUnavailable: (VMware.VimAutomation.sdk:String) [Import-Module], FileNotFoundException
Oct 20 23:23:26 cec-esxi-mgmt pwsh[6701]: + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Oct 20 23:23:26 cec-esxi-mgmt pwsh[6701]:
Oct 20 23:23:26 cec-esxi-mgmt pwsh[6701]: Import-Module : The required module 'VMware.VimAutomation.Sdk' is not loaded. Load the module or remove the module from 'RequiredModules' in the file '/usr/local/share/powershell/Modules/VMware.PowerCLI/11.4.0.14413515/VMware.Po
Oct 20 23:23:26 cec-esxi-mgmt pwsh[6701]: At line:3 char:1
Oct 20 23:23:26 cec-esxi-mgmt pwsh[6701]: + Import-Module -Name 'VMware.PowerCLI'
Oct 20 23:23:26 cec-esxi-mgmt pwsh[6701]: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Oct 20 23:23:26 cec-esxi-mgmt pwsh[6701]: + CategoryInfo : ResourceUnavailable: (/usr/local/share/po\u2026Mware.PowerCLI.psd1:String) [Import-Module], MissingMemberException
Oct 20 23:23:26 cec-esxi-mgmt pwsh[6701]: + FullyQualifiedErrorId : Modules_InvalidManifest,Microsoft.PowerShell.Commands.ImportModuleCommand
I noticed that the folder location that it is using for the VMware.PowerCLI is a root location and not a user location. The VMware.VimAutomation.sdk is installed but its in a user location and not a root location. I copied them over from the user location to root location via basic cp command:
ls /usr/local/share/powershell/Modules/
VMware.DeployAutomation VMware.VimAutomation.Core VMware.VimAutomation.Srm
VMware.ImageBuilder VMware.VimAutomation.Hcx VMware.VimAutomation.Storage
VMware.PowerCLI VMware.VimAutomation.HorizonView VMware.VimAutomation.StorageUtility
VMware.Vim VMware.VimAutomation.License VMware.VimAutomation.Vds
VMware.VimAutomation.Cis.Core VMware.VimAutomation.Nsxt VMware.VimAutomation.Vmc
VMware.VimAutomation.Cloud VMware.VimAutomation.Sdk VMware.VimAutomation.vROps
VMware.VimAutomation.Common VMware.VimAutomation.Security VMware.VumAutomation
(before this only VMware.PowerCLI and a few others were there.)
I ran it again and came up with this:
Oct 20 23:47:54 esxi-mgmt systemd[1]: Started "ESXI Snapshot management".
Oct 20 23:47:54 esxi-mgmt powershell[6797]: (6.2.3:1:80) [Perftrack_ConsoleStartupStart:PowershellCons
Oct 20 23:47:54 esxi-mgmt powershell[6797]: (6.2.3:7:80) [NamedPipeIPC_ServerListenerStarted:NamedPipe
Oct 20 23:47:54 esxi-mgmt powershell[6797]: (6.2.3:1:80) [Perftrack_ConsoleStartupStop:PowershellConso
Oct 20 23:47:55 esxi-mgmt pwsh[6797]: The type initializer for 'VMware.VimAutomation.ViCore.Util10.Set
Oct 20 23:47:55 esxi-mgmt pwsh[6797]: At /usr/local/share/powershell/Modules/VMware.VimAutomation.Sdk/
Oct 20 23:47:55 esxi-mgmt pwsh[6797]: + if ([VMware.VimAutomation.ViCore.Util10.SettingsManager]::Part
Oct 20 23:47:55 esxi-mgmt pwsh[6797]: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Oct 20 23:47:55 esxi-mgmt pwsh[6797]: + CategoryInfo : OperationStopped: (:) [], TypeInitiali
Oct 20 23:47:55 esxi-mgmt pwsh[6797]: + FullyQualifiedErrorId : System.TypeInitializationException
Oct 20 23:47:55 esxi-mgmt pwsh[6797]:
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: Import-Module : The type initializer for 'VMware.VimAutomation.S
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: At line:3 char:1
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + Import-Module -Name 'VMware.PowerCLI'
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + CategoryInfo : OperationStopped: (:) [Import-Module],
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + FullyQualifiedErrorId : System.TypeInitializationException,Mic
Oct 20 23:47:56 esxi-mgmt pwsh[6797]:
Oct 20 23:47:56 esxi-mgmt powershell[6797]: (6.2.3:9:80) [Provider_Health:ExecutePipeline.Exception.Wa
Fully Qualified Error ID = InitializeDefaultDrivesExceptio
Provider name = VimInventory
Context:
Severity = Warning
Host Name = ConsoleHost
Host Version = 6.2.3
Host ID = 30ac0891-3fbd-48b9-91e6-547a3fae12ff
Host Application = /opt/microsoft/powershell/6/pws
Engine Version = 6.2.3
Runspace ID = 70caa35c-dcb5-4277-9705-93215de3db06
Pipeline ID = 43
Command Name =
Command Type =
Script Name =
Command Path =
Sequence Number = 215
User = esxi-mgmt\root
Connected User =
Shell ID = Microsoft.PowerShell
User Data:
Oct 20 23:47:56 esxi-mgmt powershell[6797]: (6.2.3:9:80) [Provider_Health:ExecutePipeline.Exception.Wa
Fully Qualified Error ID = InitializeDefaultDrivesExceptio
Provider name = VimInventory
Context:
Severity = Warning
Host Name = ConsoleHost
Host Version = 6.2.3
Host ID = 30ac0891-3fbd-48b9-91e6-547a3fae12ff
Host Application = /opt/microsoft/powershell/6/pws
Engine Version = 6.2.3
Runspace ID = 70caa35c-dcb5-4277-9705-93215de3db06
Pipeline ID = 43
Command Name =
Command Type =
Script Name =
Command Path =
Sequence Number = 216
User = esxi-mgmt\root
Connected User =
Shell ID = Microsoft.PowerShell
User Data:
Oct 20 23:47:56 esxi-mgmt powershell[6797]: (6.2.3:9:80) [Provider_Health:ExecutePipeline.Exception.Wa
Fully Qualified Error ID = InitializeDefaultDrivesExceptio
Provider name = VimDatastore
Context:
Severity = Warning
Host Name = ConsoleHost
Host Version = 6.2.3
Host ID = 30ac0891-3fbd-48b9-91e6-547a3fae12ff
Host Application = /opt/microsoft/powershell/6/pws
Engine Version = 6.2.3
Runspace ID = 70caa35c-dcb5-4277-9705-93215de3db06
Pipeline ID = 43
Command Name =
Command Type =
Script Name =
Command Path =
Sequence Number = 217
User = esxi-mgmt\root
Connected User =
Shell ID = Microsoft.PowerShell
User Data:
Oct 20 23:47:56 esxi-mgmt powershell[6797]: (6.2.3:9:80) [Provider_Health:ExecutePipeline.Exception.Wa
Fully Qualified Error ID = InitializeDefaultDrivesExceptio
Provider name = VimDatastore
Context:
Severity = Warning
Host Name = ConsoleHost
Host Version = 6.2.3
Host ID = 30ac0891-3fbd-48b9-91e6-547a3fae12ff
Host Application = /opt/microsoft/powershell/6/pws
Engine Version = 6.2.3
Runspace ID = 70caa35c-dcb5-4277-9705-93215de3db06
Pipeline ID = 43
Command Name =
Command Type =
Script Name =
Command Path =
Sequence Number = 218
User = esxi-mgmt\root
Connected User =
Shell ID = Microsoft.PowerShell
User Data:
Oct 20 23:47:56 esxi-mgmt powershell[6797]: (6.2.3:9:80) [Command_Health:ExecutePipeline.Exception.War
Fully Qualified Error ID = System.TypeInitializationExcept
Context:
Severity = Warning
Host Name = ConsoleHost
Host Version = 6.2.3
Host ID = 30ac0891-3fbd-48b9-91e6-547a3fae12ff
Host Application = /opt/microsoft/powershell/6/pws
Engine Version = 6.2.3
Runspace ID = 70caa35c-dcb5-4277-9705-93215de3db06
Pipeline ID = 1
Command Name = Connect-VIServer
Command Type = Cmdlet
Script Name =
Command Path =
Sequence Number = 222
User = esxi-mgmt\root
Connected User =
Shell ID = Microsoft.PowerShell
User Data:
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: Connect-VIServer : The type initializer for 'VMware.VimAutomatio
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: At line:4 char:1
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + Connect-VIServer -Server 9.3.254.14 -User root -Password pinkz
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + CategoryInfo : NotSpecified: (:) [Connect-VIServer],
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + FullyQualifiedErrorId : System.TypeInitializationException,VMw
Oct 20 23:47:56 esxi-mgmt pwsh[6797]:
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: New-Snapshot : Cannot process argument transformation on paramet
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: At line:6 char:18
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + New-Snapshot -VM pkgs-mirror -Name "-snapshot-$d
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + ~~~~~~~~~~~~~~~
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + CategoryInfo : InvalidData: (:) [New-Snapshot], Param
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + FullyQualifiedErrorId : ParameterArgumentTransformationError,V
Oct 20 23:47:56 esxi-mgmt pwsh[6797]:
Oct 20 23:47:56 esxi-mgmt powershell[6797]: (6.2.3:9:80) [Command_Health:ExecutePipeline.Exception.War
Fully Qualified Error ID = System.TypeInitializationExcept
Context:
Severity = Warning
Host Name = ConsoleHost
Host Version = 6.2.3
Host ID = 30ac0891-3fbd-48b9-91e6-547a3fae12ff
Host Application = /opt/microsoft/powershell/6/pws
Engine Version = 6.2.3
Runspace ID = 70caa35c-dcb5-4277-9705-93215de3db06
Pipeline ID = 1
Command Name = Get-VM
Command Type = Cmdlet
Script Name =
Command Path =
Sequence Number = 263
User = esxi-mgmt\root
Connected User =
Shell ID = Microsoft.PowerShell
User Data:
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: Get-VM : The type initializer for 'VMware.VimAutomation.Sdk.Inte
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: At line:7 char:1
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + Get-VM pkgs-mirror | Get-Snapshot |
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + ~~~~~~~~~~~~~~~~~~~~~~
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + CategoryInfo : NotSpecified: (:) [Get-VM], TypeInitia
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + FullyQualifiedErrorId : System.TypeInitializationException,VMw
Oct 20 23:47:56 esxi-mgmt pwsh[6797]:
lines 639-661/661 (END)
Host ID = 30ac0891-3fbd-48b9-91e6-547a3fae12ff
Host Application = /opt/microsoft/powershell/6/pws
Engine Version = 6.2.3
Runspace ID = 70caa35c-dcb5-4277-9705-93215de3db06
Pipeline ID = 1
Command Name = Get-VM
Command Type = Cmdlet
Script Name =
Command Path =
Sequence Number = 263
User = esxi-mgmt\root
Connected User =
Shell ID = Microsoft.PowerShell
User Data:
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: Get-VM : The type initializer for 'VMware.VimAutomation.Sdk.Inte
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: At line:7 char:1
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + Get-VM pkgs-mirror | Get-Snapshot |
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + ~~~~~~~~~~~~~~~~~~~~~~
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + CategoryInfo : NotSpecified: (:) [Get-VM], TypeInitia
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + FullyQualifiedErrorId : System.TypeInitializationException,VMw
Oct 20 23:47:56 esxi-mgmt pwsh[6797]:
~
lines 639-661/661 (END)
Host ID = 30ac0891-3fbd-48b9-91e6-547a3fae12ff
Host Application = /opt/microsoft/powershell/6/pwsh.dll /home/user/scripts/mirror/-snapshots
Engine Version = 6.2.3
Runspace ID = 70caa35c-dcb5-4277-9705-93215de3db06
Pipeline ID = 1
Command Name = Get-VM
Command Type = Cmdlet
Script Name =
Command Path =
Sequence Number = 263
User = esxi-mgmt\root
Connected User =
Shell ID = Microsoft.PowerShell
User Data:
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: Get-VM : The type initializer for 'VMware.VimAutomation.Sdk.Interop.V1.CoreServiceFactory' threw an exception.
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: At line:7 char:1
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + Get-VM pkgs-mirror | Get-Snapshot |
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + ~~~~~~~~~~~~~~~~~~~~~~
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + CategoryInfo : NotSpecified: (:) [Get-VM], TypeInitializationException
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + FullyQualifiedErrorId : System.TypeInitializationException,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Oct 20 23:47:56 esxi-mgmt pwsh[6797]:
~
lines 639-661/661 (END)
Host ID = 30ac0891-3fbd-48b9-91e6-547a3fae12ff
Host Application = /opt/microsoft/powershell/6/pwsh.dll /home/user/scripts/mirror/-snapshots
Engine Version = 6.2.3
Runspace ID = 70caa35c-dcb5-4277-9705-93215de3db06
Pipeline ID = 1
Command Name = Get-VM
Command Type = Cmdlet
Script Name =
Command Path =
Sequence Number = 263
User = esxi-mgmt\root
Connected User =
Shell ID = Microsoft.PowerShell
User Data:
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: Get-VM : The type initializer for 'VMware.VimAutomation.Sdk.Interop.V1.CoreServiceFactory' threw an exception.
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: At line:7 char:1
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + Get-VM pkgs-mirror | Get-Snapshot |
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + ~~~~~~~~~~~~~~~~~~~~~~
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + CategoryInfo : NotSpecified: (:) [Get-VM], TypeInitializationException
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + FullyQualifiedErrorId : System.TypeInitializationException,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Oct 20 23:47:56 esxi-mgmt pwsh[6797]:
~
lines 639-661/661 (END)
Host ID = 30ac0891-3fbd-48b9-91e6-547a3fae12ff
Host Application = /opt/microsoft/powershell/6/pws
Engine Version = 6.2.3
Runspace ID = 70caa35c-dcb5-4277-9705-93215de3db06
Pipeline ID = 1
Command Name = Get-VM
Command Type = Cmdlet
Script Name =
Command Path =
Sequence Number = 263
User = esxi-mgmt\root
Connected User =
Shell ID = Microsoft.PowerShell
User Data:
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: Get-VM : The type initializer for 'VMware.VimAutomation.Sdk.Inte
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: At line:7 char:1
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + Get-VM pkgs-mirror | Get-Snapshot |
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + ~~~~~~~~~~~~~~~~~~~~~~
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + CategoryInfo : NotSpecified: (:) [Get-VM], TypeInitia
Oct 20 23:47:56 esxi-mgmt pwsh[6797]: + FullyQualifiedErrorId : System.TypeInitializationException,VMw
Oct 20 23:47:56 esxi-mgmt pwsh[6797]:
I'm kind of confused as to whats happening but it seems like when its run under the script via systemctl or cron it is attempting to execute via root and there seems to be a huge mismatch of module locations between a local user and the root user.