VMware Cloud Community
MikeAW2010
Enthusiast
Enthusiast

Snapshot storage management questions

I'm fairly new to ESXI and I'm trying to grasp how snapshots work in this environment.

From what I understand so far, it seems like they work almost like GIT repositories, where a master snapshot is created first, and then a concurrent snapshot is dependent on the master snapshot and the concurrent snapshots (child snapshots) are dependent on each snapshot taken before it making kind of a chain of dependencies. It appears that when ESXI boots a VM, it actually uses the most recent snapshot along with the vdisk and not just the vdisk, meaning the most recent snapshot must be fully intact.

Here is my question. We like to take a snapshot of a certain VM once a week but over time we do not want it to fill up and over encumber our storage capacity. My first thought was to delete any snapshot older than 2 months, but upon doing this I was no longer able to boot into the VM. I did manage to repair it by loading the original vdisk image which was months out of date, and rebuilt everything from there, however; what is the best way to manage snapshots if you seemingly cannot delete the oldest snapshot without affecting the current snapshot?

Thanks.

30 Replies
MikeAW2010
Enthusiast
Enthusiast

managed to install it, had to download libcu60 manually and dpkg it onto the server.

Now:

#! /usr/bin/pwsh

Connect-VIServer -Server x.x.x.x-User xxxx -Password xxxxxxxx

$date = Get-Date

New-Snapshot -VM xxxxxxxx -Name "apt-mirror-snapshot-$date"

Get-VM xxxxxxxx | Get-Snapshot |

Where-Object {$_.Created -lt (Get-Date).AddMonths(-2)} |

Sort-Object -Property Created |

Remove-Snapshot -Confirm:$false -RemoveChildren

Oct 16 16:58:01 CRON[15671]: (root) CMD (/home/user/scripts/mirror/mirror-snapshots)

Oct 16 16:58:01 powershell[15672]: (6.2.3:1:80) [Perftrack_ConsoleStartupStart:PowershellConsoleStartup.WinStart.Informational] PowerShell console is starting up

Oct 16 16:58:01 powershell[15672]: (6.2.3:6:80) [NamedPipeIPC_ServerListenerStarted:NamedPipe.Open.Informational] Windows PowerShell has started an IPC listening thread on process: 15672 in AppDomain: None.

Oct 16 16:58:01 powershell[15672]: (6.2.3:1:80) [Perftrack_ConsoleStartupStop:PowershellConsoleStartup.WinStop.Informational] PowerShell console is ready for user input

Oct 16 16:58:02 postfix/pickup[15193]: 82B1652031E: uid=0 from=<root>

Oct 16 16:58:02 postfix/cleanup[15690]: 82B1652031E: message-id=<20191016215802.82B1652031E@cec-esxi-mgmt>

Oct 16 16:58:02 postfix/qmgr[14472]: 82B1652031E: from=<root@*******>, size=2012, nrcpt=1 (queue active)

Oct 16 16:58:02 postfix/local[15692]: 82B1652031E: to=<root@*******>, orig_to=<root>, relay=local, delay=0.01, delays=0.01/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)

Oct 16 16:58:02 postfix/qmgr[14472]: 82B1652031E: removed

Still seems to be the same issue.

I also removed the installation from snap

sudo snap remove powershell

Any other possibilities?

0 Kudos
MikeAW2010
Enthusiast
Enthusiast

I hashed out the job in cron after experimenting awhile for a bit. I created a new one in systemctl timer.

Timer:

[Unit]

Description=Create Snapshots

[Timer]

OnCalendar=*:0/2

Persistent=true

[Install]

WantedBy=multi-user.target

Service:

[Unit]

Description="ESXI Snapshot management"

[Service]

ExecStart=/usr/bin/pwsh /home/user/scripts/mirror/snapshot-mgmt

This is the error I'm getting, it seems like PowerCLI is unable to see its modules when run from an automated script:

Oct 17 14:43:08 vm-mgmt systemd[1]: Started "VM Snapshot management".

Oct 17 14:43:08 vm-mgmt powershell[2296]: (6.2.3:1:80) [Perftrack_ConsoleStartupStart:PowershellConsoleStartup.WinStart.Informational] PowerShell console is starting up

Oct 17 14:43:08 vm-mgmt powershell[2296]: (6.2.3:6:80) [NamedPipeIPC_ServerListenerStarted:NamedPipe.Open.Informational] Windows PowerShell has started an IPC listening thread on process: 2296 in AppDomain: None.

Oct 17 14:43:08 vm-mgmt powershell[2296]: (6.2.3:1:80) [Perftrack_ConsoleStartupStop:PowershellConsoleStartup.WinStop.Informational] PowerShell console is ready for user input

Oct 17 14:43:08 vm-mgmt pwsh[2296]: Connect-VIServer : The term 'Connect-VIServer' is not recognized as the name of a cmdlet, function, script file, or operable program.

Oct 17 14:43:08 vm-mgmt pwsh[2296]: Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Oct 17 14:43:08 vm-mgmt pwsh[2296]: At line:2 char:1

Oct 17 14:43:08 vm-mgmt pwsh[2296]: + Connect-VIServer -Server X.X.X.X -User xxxx -Password xxxxxxxxx

Oct 17 14:43:08 vm-mgmt pwsh[2296]: + ~~~~~~~~~~~~~~~~

Oct 17 14:43:08 vm-mgmt pwsh[2296]: + CategoryInfo          : ObjectNotFound: (Connect-VIServer:String) [], CommandNotFoundException

Oct 17 14:43:08 vm-mgmt pwsh[2296]: + FullyQualifiedErrorId : CommandNotFoundException

Oct 17 14:43:08 vm-mgmt pwsh[2296]: 

Oct 17 14:43:09 vm-mgmt pwsh[2296]: New-Snapshot : The term 'New-Snapshot' is not recognized as the name of a cmdlet, function, script file, or operable program.

Oct 17 14:43:09 vm-mgmt pwsh[2296]: Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Oct 17 14:43:09 vm-mgmt pwsh[2296]: At line:4 char:1

Oct 17 14:43:09 vm-mgmt pwsh[2296]: + New-Snapshot -VM mirror -Name "apt-mirror-snapshot-$date"

Oct 17 14:43:09 vm-mgmt pwsh[2296]: + ~~~~~~~~~~~~

Oct 17 14:43:09 vm-mgmt pwsh[2296]: + CategoryInfo          : ObjectNotFound: (New-Snapshot:String) [], CommandNotFoundException

Oct 17 14:43:09 vm-mgmt pwsh[2296]: + FullyQualifiedErrorId : CommandNotFoundException

Oct 17 14:43:09 vm-mgmt pwsh[2296]: 

Oct 17 14:43:09 vm-mgmt pwsh[2296]: Get-VM : The term 'Get-VM' is not recognized as the name of a cmdlet, function, script file, or operable program.

Oct 17 14:43:09 vm-mgmt pwsh[2296]: Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Oct 17 14:43:09 vm-mgmt pwsh[2296]: At line:5 char:1

Oct 17 14:43:09 vm-mgmt pwsh[2296]: + Get-VM mirror | Get-Snapshot |

Oct 17 14:43:09 vm-mgmt pwsh[2296]: + ~~~~~~

Oct 17 14:43:09 vm-mgmt pwsh[2296]: + CategoryInfo          : ObjectNotFound: (Get-VM:String) [], CommandNotFoundException

Oct 17 14:43:09 vm-mgmt pwsh[2296]: + FullyQualifiedErrorId : CommandNotFoundException

Oct 17 14:43:09 vm-mgmt pwsh[2296]: 

Yet when run manually, it works fine. Is there anything else I can check?

0 Kudos
LucD
Leadership
Leadership

I suspect the module path might be missing in $env:PSModulePath.

Can you check what is in that variable?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

MikeAW2010
Enthusiast
Enthusiast

When run directly from PS:

PS /home/user/scripts/mirror> $env:PSModulePath

/home/user/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/6/Modules

When run as a script from Ubuntu Shell:

user@esxi-mgmt:~/scripts/mirror$ /usr/bin/pwsh /home/user/scripts/mirror/ModulePath

/home/user/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/6/Modules

When run from systemctl:

     Service:

[Unit]

Description="Tests module path in PS"

[Service]

ExecStart=/usr/bin/pwsh /home/user/scripts/mirror/ModulePath

     Output:

Oct 17 15:43:06 esxi-mgmt systemd[1]: Started "Tests module path in PS".

Oct 17 15:43:06 esxi-mgmt powershell[2674]: (6.2.3:1:80) [Perftrack_ConsoleStartupStart:PowershellConsoleStartup.WinStart.Informational] PowerShell console is starting

Oct 17 15:43:06 esxi-mgmt powershell[2674]: (6.2.3:6:80) [NamedPipeIPC_ServerListenerStarted:NamedPipe.Open.Informational] Windows PowerShell has started an IPC listen

Oct 17 15:43:06 esxi-mgmt powershell[2674]: (6.2.3:1:80) [Perftrack_ConsoleStartupStop:PowershellConsoleStartup.WinStop.Informational] PowerShell console is ready for

Oct 17 15:43:06 esxi-mgmt pwsh[2674]: /tmp/437512a5-a1a6-429d-8076-6835cae74c74/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/6/Modules

0 Kudos
LucD
Leadership
Leadership

Now the next thing to check is where are the PowerCLI modules located?
Are they in one of these folders?
Also when running from systemctl?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

MikeAW2010
Enthusiast
Enthusiast

For the folders that PS is looking through after initiated via systemctl:

user@esxi-mgmt:~$ ls /tmp/437512a5-a1a6-429d-8076-6835cae74c74/.local/share/powershell/Modules

##The Modules folder is an empty folder, also this directly only appears when running via automation over systemctl and nowhere else.

user@esxi-mgmt:~$ ls /usr/local/share/powershell/Modules

ls: cannot access '/usr/local/share/powershell/Modules': No such file or directory

##Folder doesn't even exist.

user@esxi-mgmt:~$ ls /usr/local/share/powershell/

Scripts

##Confirming it does not exist.

user@esxi-mgmt:~$ ls /opt/microsoft/powershell/6/Modules

Microsoft.PowerShell.Archive  Microsoft.PowerShell.Management  Microsoft.PowerShell.Utility  PowerShellGet                PSReadLine

Microsoft.PowerShell.Host     Microsoft.PowerShell.Security    PackageManagement             PSDesiredStateConfiguration  ThreadJob

##Modules exist here, this source is also present in the remaining sources

Run directly from PS or script from shell promp:

user@esxi-mgmt:~$

user@esxi-mgmt:~$ ls /home/user/.local/share/powershell/Modules

ls: cannot access '/home/user/.local/share/powershell/Modules': No such file or directory

user@esxi-mgmt:~$

user@esxi-mgmt:~$ ls /home/user/.local/share/powershell

ls: cannot access '/home/user/.local/share/powershell': No such file or directory

user@esxi-mgmt:~$

user@esxi-mgmt:~$ ls /usr/local/share/powershell/Modules

ls: cannot access '/usr/local/share/powershell/Modules': No such file or directory

user@esxi-mgmt:~$

user@esxi-mgmt:~$ /opt/microsoft/powershell/6/Modules

-bash: /opt/microsoft/powershell/6/Modules: Is a directory

user@esxi-mgmt:~$ ls /opt/microsoft/powershell/6/Modules

  1. Microsoft.PowerShell.Archive  Microsoft.PowerShell.Management  Microsoft.PowerShell.Utility  PowerShellGet                PSReadLine
  2. Microsoft.PowerShell.Host     Microsoft.PowerShell.Security    PackageManagement             PSDesiredStateConfiguration  ThreadJob
0 Kudos
MikeAW2010
Enthusiast
Enthusiast

Incase these modules aren't properly loading, is there a way to summon them in my script?

0 Kudos
LucD
Leadership
Leadership

Yes, you can do an Import-Module and provide the path to the module folder.

Try something like this (path depends of course on where you installed the modules)

Import-Module -Name '/home/PowerCLI/Modules/VMware.PowerCLI'


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

MikeAW2010
Enthusiast
Enthusiast

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.

0 Kudos
MikeAW2010
Enthusiast
Enthusiast

I think I finally fixed it, after realizing the path discrepancies between the local user and root when executing powershell, I decided to use a non sudo crontab -e - so basically just a crontab -e instead of sudo crontab -e as to keep pathing all under the local user and it executed and created the snapshot as intended.

Thanks for your help all!

0 Kudos