Archive by category "Automation"

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

 

Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available

Yesterday I was facing this error when running a SMA Runbook with the invoke-webrequest cmdlet. For troubleshooting I had to enable SMA script logging for this runbook so I was able to see wats going wrong. The error says you must run the “getting started setup” of internet explorer for the service account which is running the scripts.

 

This is not ideally when you run this script on multiple servers. Now there are 2 options available to ignore this stupid error:

1. Enable the Group policy object (GPO) for Prevent running first run wizard. This setting is in “Computer configuration -> Policies -> Administrative templates -> Windows Components -> Internet Explorer”. Set the “Prevent running first run wizard” to enabled.

2. Run the Invoke-webrequest with the –UseBasicParsing CMDlet.

 

 

PowerShell: The specified string is not in the form required for a subject

During the creation of a PowerShell SMA Runbook I was getting the following error message. This error appear when sending an automatic mail message with the send-mailmessage cmdlet. It only happens when the subject is filled with a String parameter which contains invalid characters.

After two hours of troubleshooting I formatted the string with the following regex which worked in my case: