As it combines VBA and AppleScript, I might need the script from this in the future [WayBack] Word for Mac 2011: create macro or shortcut to ‘Insert Picture – Microsoft Community.
–jeroen
Posted by jpluimers on 2021/11/02
As it combines VBA and AppleScript, I might need the script from this in the future [WayBack] Word for Mac 2011: create macro or shortcut to ‘Insert Picture – Microsoft Community.
–jeroen
Posted in Development, Office, Office 2011 for Mac, Office Automation, Office VBA, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/10/28
After doing a lot of – historically grown – dash scripting for ESXi, I found out there is Python available on ESXi:
Yes I know that Python 3.5 is end-of-life (and 3.5.10 was the latest version), but it is a lot better than shell scripts.
So now some links for my list of things to try in order to use Python for scripting ESXi operations:
Take a look at the pyVmomi project which is the official Python SDK for the VMware vSphere API that allows you to manage ESX, ESXi and vCenter.
Moreover, the pyvmomi-community-samples repository contains lot of examples.
Also, checkout the pyvmomi Community Samples repo. It has all kinds of great samples, including one that could fit this request: github.com/vmware/pyvmomi-community-samples/blob/master/samples/… – [Wayback] Kyle Ruddy
Welcome to the pyvmomi-community-samples project
This is a place for anyone to learn about working with the vSphere Management SDK’s native python binding library pyVmomi. Samples here are contributed by developers like you and curated by your fellow developers. The quality and validity of the samples will vary, however, if you see a problem report it! If you can solve someone’s problem, contribute a fix! If you need a new sample ask for one!
pyVmomi is the Python SDK for the VMware vSphere API that allows you to manage ESX, ESXi, and vCenter.
Executable Samples
This directory contains a collection of executable sample scripts that use the pyVmomi library. There is atoolsdirectory that holds a collection of tools and atestsdirectory that holds the tests for those tools.Quality and License
Scripts are provided as-is by numerous contributors and the status of any sample at any point is subject to change. The project is intended as a collaborative exercise in community learning and may not contain best practice methods.All samples revert to the license of the project and all ownership reverts to the community project.Contribution Notes
- If a script is in this directory, it is an executable sample.
- conform to pep8
- avoid using any special tools beyond pyVmomi.
- do not extend the pyVmomi API in this project we have two separate projects dedicated to that.
- tests are appreciated but optional because of this sample quality must be manually assessed bug reports and fixes are much appreciated.
- A reviewer will pull a new sample for testing and will attempt to run the sample. If the reviewer can do this, the sample can be merged
Getting Help
- Question can be opened as issues at https://github.com/vmware/pyvmomi-community-samples/issues
- The IRC forum #pyvmomi is for developers working with pyVmomi
of which there are many, for instance:
Any reusable classes or methods that you develop can be included in packages under this directory. When adding a reusable component we highly recommend that you include tests.Only some samples will make use of reusable components. This is where to put those.
–jeroen
Posted in *nix, *nix-tools, ash/dash, ash/dash development, Development, Power User, Python, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/10/27
For my link archive; I started with [Wayback] dash get all parameters quoted – Google Search:
Parameter(s) Description $0the first positional parameter, equivalent to argv[0]in C, see the first argument$FUNCNAMEthe function name (attention: inside a function, $0is still the$0of the shell, not the function name)$1 … $9the argument list elements from 1 to 9 ${10} … ${N}the argument list elements beyond 9 (note the parameter expansion syntax!) $*all positional parameters except $0, see mass usage$@all positional parameters except $0, see mass usage$#the number of arguments, not counting $0These positional parameters reflect exactly what was given to the script when it was called.
Option-switch parsing (e.g.
-hfor displaying help) is not performed at this point.See also the dictionary entry for “parameter”.
Syntax Effective result $*$1 $2 $3 … ${N}$@$1 $2 $3 … ${N}"$*""$1c$2c$3c…c${N}""$@""$1" "$2" "$3" … "${N}"
The
$@variable expands to all command-line parameters separated by spaces. Here is an example.abc "$@"When using
$@, you should (almost) always put it in double-quotes to avoid misparsing of arguments containing spaces or wildcards (see below). This works for multiple arguments. It is also portable to all POSIX-compliant shells.It is also worth nothing that
$0(generally the script’s name or path) is not in$@.The Bash Reference Manual Special Parameters Section says that
$@expands to the positional parameters starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is"$@"is equivalent to"$1" "$2" "$3"....
If the arguments are to be stored in a script variable and the arguments are expected to contain spaces, I wholeheartedly recommend employing a
"$*"trick with the input field separator set to tabIFS=$'\t'[Wayback].
and comment by Serge as well:
Here is [Wayback] an example, which includes quoted input. The input also matters!
Use
"$@"instead of plain$@if you actually wish your parameters to be passed the same.Observe:
$ cat no_quotes.sh #!/bin/bash echo_args.sh $@ $ cat quotes.sh #!/bin/bash echo_args.sh "$@" $ cat echo_args.sh #!/bin/bash echo Received: $1 echo Received: $2 echo Received: $3 echo Received: $4 $ ./no_quotes.sh first second Received: first Received: second Received: Received: $ ./no_quotes.sh "one quoted arg" Received: one Received: quoted Received: arg Received: $ ./quotes.sh first second Received: first Received: second Received: Received: $ ./quotes.sh "one quoted arg" Received: one quoted arg Received: Received: Received:
–jeroen
Posted in *nix, *nix-tools, ash/dash, ash/dash development, bash, bash, Development, ESXi6, ESXi6.5, ESXi6.7, ESXi7, Power User, Scripting, Software Development, Virtualization, VMware, VMware ESXi | Leave a Comment »
Posted by jpluimers on 2021/10/26
This is sort of a follow-up on VMware ESXi console: viewing all VMs, suspending and waking them up: part 4 which already gave part of the configuration details of all the configured VMs.
Back then, we ended with this:
List the
vmidvalues, power status and name of all VMsBack to the listing script
vim-cmd-list-all-VMs.sh:#!/bin/sh # https://wiert.me/2021/04/29/vmware-esxi-console-viewing-all-vms-suspending-and-waking-them-up-part-4/ vmids=`vim-cmd vmsvc/getallvms | sed -n -E -e "s/^([[:digit:]]+)\s+((\S.+\S)?)\s+(\[\S+\])\s+(.+\.vmx)\s+(\S+)\s+(vmx-[[:digit:]]+)\s*?((\S.+)?)$/\1/p"` for vmid in ${vmids} ; do powerState=`vim-cmd vmsvc/power.getstate ${vmid} | sed '1d'` name=`vim-cmd vmsvc/get.config ${vmid} | sed -n -E -e '/\(vim.vm.ConfigInfo\) \{/,/files = \(vim.vm.FileInfo\) \{/ s/^ +name = "(.*)",.*?/\1/p'` vmPathName=`vim-cmd vmsvc/get.config ${vmid} | sed -n -E -e '/files = \(vim.vm.FileInfo\) \{/,/tools = \(vim.vm.ToolsConfigInfo\) \{/ s/^ +vmPathName = "(.*)",.*?/\1/p'` echo "VM with id ${vmid} has power state ${powerState} (name = ${name}; vmPathName = ${vmPathName})." done
It uses vim-cmd vmsvc/getallvms, vim-cmd vmsvc/power.getstate and vim-cmd vmsvc/get.config with some sed and a for loop from dash to generate a nice list of information.
A long time ago, I already figured out that vim-cmd vmsvc/get.guest # gives all guest information including network information for a running VM that has either VMware Tools or open-vm-tools running (see VMware ESXi console: viewing all VMs, suspending and waking them up: part 3 for the difference between these two tools).
A full output of a sample VM is below the signature.
There are a few places that have the LAN ipAddress. For now, I choose to use only the IPv4 main address from ipAddress, which is in between (vim.vm.GuestInfo) { and net = (vim.vm.GuestInfo.NicInfo) [.
I modified the above script to become this:
Posted in *nix, *nix-tools, ash/dash, ash/dash development, Development, ESXi6, ESXi6.5, ESXi6.7, ESXi7, find, Power User, Scripting, sed, sed script, Software Development, Virtualization, VMware, VMware ESXi | Leave a Comment »
Posted by jpluimers on 2021/10/26
I needed a way to append the directory of a script to the path as all my tool scripts are in there, and I did not want to modify any profile scripts as these might be modified during ESXi upgrade.
First you need the full script filename through readlink then toe parent directory name through dirname:
me@pc:~$ readlink -f $(which sh)
/bin/dash
By [Wayback] Vanni Totaro.
# echo 'test/90_2a5/Windows' | xargs dirname | xargs basename90_2a5
Note there might be dragons with more symlinks or different shells:
I created the script below. It is not perfect, but for my situation it gets the job done.
If you do not start a new shell, then the export is lost as a new dash shell process is started for each script that runs from the terminal or console.
# cat /opt/bin/append-script-directory-to-path-and-start-new-shell.sh #!/bin/sh # Absolute path to this script, e.g. /home/user/bin/foo.sh # echo "'$0'" SCRIPT=$(readlink -f "$0") # Absolute path this script is in, thus /home/user/bin SCRIPTPATH=$(dirname "$SCRIPT") # echo Appending to $PATH: $SCRIPTPATH export PATH=$PATH:$SCRIPTPATH sh
–jeroen
Posted in *nix, *nix-tools, ash/dash, ash/dash development, Development, ESXi6, ESXi6.5, ESXi6.7, ESXi7, Power User, Scripting, Software Development, Virtualization, VMware, VMware ESXi | Leave a Comment »
Posted by jpluimers on 2021/10/21
I need to write some tests for this, but it looks like you can use the keywords Begin/Process/End with code blocks when the script block is inside a .ForEach member call.
The behaviour seems to be the same as if these blocks are part of a function that executes inside a pipeline (Begin and End are executed once; Process is executed for each item in the pipeline).
It’s hard to Google on this, as all hits of all queries I tried got me into these keywords in the context of functions.
The below links are on my reading list.
Microsoft documentation:
SS64 docs (which has guidance on which of the 3 foreach constructs to use when):
ForEach and %)Social media and blog posts:
$array.ForEach({}) | Saved KeystrokesStackOverflow entries:
I know this is truly old, but here’s a function I added to my Profile to facilitate registry exploration:
Function Get-KeyProperty { Param( [Parameter(Mandatory=$true,ValueFromPipeline=$true)] [ValidateScript( {(Resolve-Path $_).Provider.Name -Like 'Registry'} )] [String[]] $Path, [String[]] $Name=@("*") ) Process { $Name.ForEach({ (Get-Item $Path).Property -like $_}).ForEach({ Begin {$Hash = @{}} Process { $Hash += @{ $_ = (Get-Item $Path).GetValue($_)} } End {[PSCustomObject]$Hash} }) }}…
–jeroen
Posted in CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/10/13
On nx, I’m used to xargs which allows to convert from a pipe of output into arguments passed to a command. This is useful, as many commands only accept arguments as parameters.
In PowerShell, you can usually avoid an xargs equivalent because commandlet output is a stream of objects that you can post-process using . I for instance used that in PowerShell: recovering from corrupt empty *.nupkg files after a disk was accidentally full during update.
Here are some xargs equivalency examples:
Posted in *nix, *nix-tools, bash, CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, xargs | Leave a Comment »
Posted by jpluimers on 2021/10/13
Anders Hejlsberg: software legend.
–jeroen
Posted in .NET, C#, Development, Pascal, Software Development, Turbo Pascal, TypeScript | Leave a Comment »
Posted by jpluimers on 2021/10/12
For my link archive:
I also need to check out [WayBack] Martin Farach-Colton – Wikipedia, as his algorithm is likely more optimised and more versatile.
–jeroen
Posted in .NET, Algorithms, C#, Development, JavaScript/ECMAScript, Ruby, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/10/12
After watching an autologon system not logging on automatically over the past years, the pattern seems to be that at least major, and some less minor Windows updates remove autlogon parts of the registry.
I’m not sure where the boundary between “major” and “less minor” lies (though I suspect “cumulative updates” and larger), nor if more than these values are affected:
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
AutoAdminLogon gets removed or becomes value 0DefaultUserName gets removedDefaultPassword gets removedThis means that now after each startup, I need to schedule a task that runs a script setting the values I need depending if a password is needed or not.
The script also needs credentials, so I need to figure out how to properly do that.
I still need to decide between PowerShell or batch file script, as I already have the batch file from How to turn on automatic logon in Windows and automatic logon in Windows 2003.
For my future reference, some more links on things that can get deleted:
- [WayBack] Windows Update deletes custom registry settings
- [WayBack] Windows 10 update deletes the registry Run command – Super User
- [WayBack] Windows 10 May Delete Your Programs Without Asking
- [WayBack] Don’t break Windows 10 by deleting SID, Microsoft warns – Naked Security
- [WayBack] Windows 10 KB4532693 Update Bug Hides User Data, Loads Wrong Profile
- [WayBack] why has the latest windows update moved all my files into another user – Microsoft Community
Hopefully these links will help me writing the scripts:
For several reasons, mostly security-related, PowerShell scripts aren’t as easily portable and usable as batch scripts can be. However, we can bundle a batch script with our PowerShell scripts to work around these issues. Here, we’ll show you a few of those problem areas, and how to build a batch script to get around them.
–jeroen
Posted in Batch-Files, CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows, Windows 10, Windows Development | Leave a Comment »