Archive for the ‘Powershell’ Category

Docker for Windows start-up error

September 25th, 2016 1 comment

After installing Docker for Windows I was unable to run it, following error appeared.


Unable to create: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: The specified module 'Hyper-V' was not loaded because no valid module file was found in any module directory.
at <ScriptBlock>, <No file>: line 76
 at Docker.Backend.HyperV.RunScript(String action, Dictionary`2 parameters)
 at Docker.Backend.ContainerEngine.Linux.Start(Settings settings)
 at Docker.Core.Pipe.NamedPipeServer.<>c__DisplayClass8_0.<Register>b__0(Object[] parameters)
 at Docker.Core.Pipe.NamedPipeServer.RunAction(String action, Object[] parameters)</pre>

I checked that Hyper-V was installed but it seems that Docker also needs to have the Powershell tools installed. So activate the feature and Docker will run fine 🙂


VMWare PowerCLI script: increase RAM and update VMWare Tools

January 11th, 2016 No comments

The other day I had to increase the memory of 30 virtual servers and install the latest VMWare tools. Instead of doing this manually I uses PowerCLI.

Put the serverlist in a *.txt file that is located in the same folder as the PowerShell script. This will shutdown the server, increase the RAM to 4GB, start the server and then upgrade the VMWare tools.

$servers = Get-Content -Path E:\path_to_my_folder\server_list.txt

get-vm $servers | Shutdown-VMGuest –Confirm:$False

sleep 150

Get-VM $servers | Set-VM –MemoryGB 4 –Confirm:$False | Start-VM

sleep 120

Get-VM $servers | Update-tools -RunAsync

PowerShell: count items per folder

August 26th, 2010 No comments

This script is created to count how many folders exist in a NAS Share. It loads the list from SQL Server and writes the result back to the same table. You can modify it to your own needs.

# **********************************************
# Created by Sébastien Morel
# Last update: August 26th, 2010
# Version 1.00
# This script will loop NAS Folders
# and return number of homefolders per share
# **********************************************

# retrieve NAS Folders
$sqlsvr = '&lt;MySQLServer&gt;'
$database = '&lt;MySQLDB&gt;'
$table = 'tbl_homeshares_trees'

Write-Host &quot;Please wait a moment, this can take a while...&quot;
Write-Host &quot; &quot;

#Create SQL Connection
Write-Verbose &quot;Creating SQL Connection...&quot;
$conn = New-Object System.Data.SqlClient.SqlConnection(&quot;Data Source=$sqlsvr;Initial Catalog=$database; Integrated Security=SSPI&quot;)
$conn2 = New-Object System.Data.SqlClient.SqlConnection(&quot;Data Source=$sqlsvr;Initial Catalog=$database; Integrated Security=SSPI&quot;)

$cmd = $conn.CreateCommand()
$cmd2 = $conn2.CreateCommand()

$cmd.CommandText = &quot;select tree_id, tree_path from $table&quot;
$Reader = $cmd.ExecuteReader()

while ($Reader.Read()) {
	$sID = $Reader[&quot;tree_id&quot;].Tostring()
	$sPath = $Reader[&quot;tree_path&quot;].Tostring()
	Write-Host &quot;Querying $sPath...&quot;
	$sGo = Get-ChildItem $sPath
	# update table
	$cmd2.CommandText = &quot;UPDATE $table SET tree_count = &quot; + $sGo.Count + &quot; WHERE tree_id = '&quot; + $sID + &quot;'&quot;
	$cmd2.ExecuteNonQuery() | Out-Null


The results in the database

Categories: Powershell Tags: ,

PowerShell: delete files older than x days

August 25th, 2010 1 comment

Classical script and we all need it some day. Edit the folder path and adjust the number of days to your clean-up schedule. The script works recursive so it will also clean-up subfolders.

As always, make sure you can execute PowerShell scripts

Set-ExecutionPolicy RemoteSigned

The Script…

$Now = Get-Date
$Days = &quot;30&quot;
$TargetFolder = &quot;C:WINDOWSsystem32LogFiles&quot;
$LastWrite = $Now.AddDays(-$days)
$Files = get-childitem $TargetFolder -include *.log, *.txt -recurse | Where {$_.LastWriteTime -le &quot;$LastWrite&quot;} 

foreach ($File in $Files){
	write-host &quot;Deleting File $File&quot; -foregroundcolor &quot;Red&quot;;  Remove-Item $File | out-null
Categories: Powershell Tags: , ,

Powershell WMI Explorer

August 20th, 2010 No comments

WMI was in the past commonly used for scripting tasks and sometimes it handy to know which classes are installed on a server/workstation. Today I found a WMI GUI that was written in Powershell by Marc van Orsouw. He has a blog called The PowerShell Guy and you can download it from here!

Categories: Powershell Tags:

Powershell v2 released for pre Windows 7 machines

August 12th, 2010 No comments

Windows Management Framework, which includes Windows PowerShell 2.0, WinRM 2.0, and BITS 4.0, was officially released to the world this morning. By providing a consistent management interface across the various flavors of Windows, we are making our platform that much more attractive to deploy. IT Professionals can now easily manage their Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7, and Windows Server 2008 R2 machines through PowerShell remoting – that’s a huge win!

You can download the packages here:

Categories: Powershell Tags:

Powershell: check installed version

August 12th, 2010 No comments

It might be usefull to know which version of Powershell is installed on your server / desktop.
Open a dos-prompt and then open a PowerShell session. There are 3 ways to check the installed version

Method 1


Method 2


Method 3 (works only with v2)


Categories: Powershell, Scripts Tags: , ,