Archive by category "Automation"

Automatic way of making a lot of folders

There are multiple reasons why you need a lot of pre-created folders. Making the folders by hand would be a very boring time intensive job. So make use of the available script languages in your system. I have written some examples below.

Create multiple folders with PowerShell

Create multiple folders with CMD

Create multiple folders on Unix

New-VM Value cannot be null. Parameter name: source

The following error: “parameter name source cannot be null” is just an exception in the VMWare.VimAutomation.Core module.
With this error its hard to find the actual issue. The version i’ve running:

The actual issue is that there is no  “-NetworkName” or -PortGroup parameter is given. So adding this wil fix the issue.

Just curious so i updated the module to the newest available.
Updated VMware.VimAutomation.Core to version: 11.5
Now the error is more clear.

My test command:

Error: New-VM: PowerCLI could not automatically determine a network to which to attach the VM. Specify a network explicitly using the -NetworkName parameter.

In the newest PowerCli version the error is more clear.
Add a -NetworkName or -PortGroup to fix the error.

Happy Automating 🙂

PowerShell: Execution of scripts is disabled on this system.

This error occur when the default PowerShell execution policy is active on the system, the default policy is restricted on fresh Windows Installations. Windows Execution policy is a security mechanism from Microsoft to protect your system against running unwanted PowerShell scripts on your system. But not handy for system administrators like us. To disable this security and enabling the possibility of running PowerShell scripts you can run a simple PowerShell command.

As described in the Help file of command: Get-ExecutionPolicy

* The execution policy is part of the security strategy of Windows PowerShell. It determines whether you can load configuration files (including your Windows PowerShell profile) and run scripts, and it determines which scripts, if any, must be digitally signed before they will run.

The effective execution policy is determined by the policies that you set by using the Set-ExecutionPolicy cmdlet and the “Turn on Script Execution” group policies for computers and users. The precedence order is ComputerGroup Policy > User Group Policy > Process (session) execution policy > User execution policy > Computer execution policy. For more information about Windows PowerShell execution policy, including definitions of the Windows PowerShellpolicies, see about_Execution_Policies

See about_Execution_Policies (http://go.microsoft.com/fwlink/?LinkID=135170).
Personally I use the following command, because I can read scripts and see if they are OK:

If you want some kind of security and run only scripts from trusted publishers.

Install git with PowerShell on Windows

With the following PowerShell function you can download and install git using PowerShell.

It downloads the latest “stable” git release to the given temp directory and installs it with default parameters.

Another and more easy way is using the package manager Chocolatey.
The Script:

Invoke-VMScript: An error occurred while sending the request

After upgrading the PowerShell module to the latest version now available (11.3.0.13964823), my invoke-vmscript goes wrong. The following exception occurs:

Finally after a couple hours of troubleshooting, parameter checking and reinstalls we found the issue. The issue is caused by a untrusted certificate of the VMWare VCenter server.

To solve this the “recommended” way: Check and fix your certificates on your system and VCenter server.
The dirty “not recommended” way: Add the following code to your script.

How to use credentials in a PowerShell script?

A nightmare for many security auditors are the plain tekst Passwords in PowerShell scripts. Offcourse this is not nessecary, we can encrypt this in local files.

But there is a difference how to encrypt passwords. Tou can encrypt it with your “user account key” or system wide with a “MachineKeyStore”.
The second one (machine key) is handy when you need to run scheduled PowerShell scripts under different user accounts.

Save plain text password with Machine Key encryption using PowerShell.

Save plain text password with User Key encryption using PowerShell.

WARNING: The names of some imported commands from the module “” include unapproved verbs that might make them less discoverable.

When you use one of the VERB types in your brand new function names, you get the following very annoying message:

WARNING: The names of some imported commands from the module ‘Set-ROBVIT-Function’ include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.

In this case “set” is our problem.
Tried to do with the -WarningAction:SilentlyContinue, -ErrorAction:SilentlyContinue, out-null parameters with no succes.
It costs me 5 Google’s to find the solution, thats why i created this little reminder to myself :).

How to solve the issue?

Fist option:
You can make some PowerShell module / function config files, with export functions etc.
To much work for my little function.

Second option (the easy one):
Just import the module with the -DisableNameChecking parameter.

If you have a better solution, dont hesitate to comment below.

Veeam backup copy to multiple offline external disks

Wondering how to create an offline disk back-up copy with more than one USB Disk? And not want to spend your IT budget on “Veeam cloud connect” This is originally not possible with the Veeam GUI because you can’t map 1 backup copy job against 2 USB disks. The job will fail because Veeam cant find one incremental which one is copied on the second USB disk which is on a safe place @home. I made a script for enabling and disabling the right copy job for each mapped USB disk.

 

No mapping between account names and security IDs was done.

Last day’s very busy with a small DevOps project in our company. Automating “bare metal deployment” of new Hyper-V Servers. We deploy the software with a combination of MDT and the brand new HP (finally) PowerShell commands.

During the step of renaming and joining the new server we faced the following error:
Computer failed to join domain ” from its current workgroup ‘WORKGROUP’ with following error message: No mapping between account names and security IDs was done.

After some troubleshooting we found a solution, by adding the two options: JoinWithNewName and AccountCreate
Renaming computer PowerShell and Joining a domain with PowerShell