Posts tagged "powershell"

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

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:

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.

Windows task scheduler: The operator or administrator has refused the request

After implementing scheduled tasks on server 2016 and 2019 we have sometimes the following annoying message. Trying literally everything. Finally we did solve this by adding an extra checkmark in the “settings” tab.

Check the box:
“Run task as soon as possible after a scheduled start is missed.”


Running Powershell scripts with the task scheduler

Program/script: powershell.exe
Added arguments: -ExecutionPolicy Unrestricted -file “c:\scripts\somescript.ps1”

Generate CPU Load with PowerShell

In some situations you need to stress your system a little (for example: to check if your monitoring is functioning properly.)

Installing some random .exe files from some anonymous websites is not always a good idea. So hereby a little script for blowing your CPU to 100%.

The script creates a nice calculation for all of your “Windows Logical Processors”

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.

Check DNS Entries with PowerShell

In a dynamic environment it’s hard to keep your DNS up-to-date. Updating the DNS server is a task which is mostly forgotten during server maintenance.
Created just a simple one-liner for checking the registered suffix and do a ping test.

Yeah I know this one is not dummy proof, but hey! t helped me checking 10.000 records in 2 minutes, so maybe i can help someone with sharing this. 🙂

 

Add new email alias Office365

One of our customers changed the company name. So the alias of all there SharedMailboxes on office365 needed to be changed. This script below contains 2 functions, the fist one is for adding an extra alias to the mailbox and the second one is for activating the new alias. This is the first time i scripted against office365, so it could be that the script is not faultyproof. But hey, its a beginning. Saved about 10 hours of manual clicking during the critical company name change.