‘Get-ChildItem’ cmdlet gets you the contents of any given path and then you can perform your next desired actions on them.

In my case, I have to get into the particular folder and need to find out all exe and msi files to install in the system. Usually when we get into any folder there could be again child folders and folders, in this case we can use ‘-Recurse’ parameter with Get-ChildItem which basically helps to get into all child folder and gets you your desired output. ‘-Include’ and ‘-Exclude’ parameters name suggests what’s the use of these.

OK let’s see below script to get all msi and exe file from particular path and install the same on system-

$path = "D:\Softwares\MyPackage\ISOImage\Prerequisites\"
$IncludeExe = @("*.exe", "*.msi")
$ExcludeExe = @("SQL*", "SS*")
$foldercontents = Get-ChildItem -Path $path -File -include $IncludeExe -exclude $ExcludeExe -Recurse
if($foldercontents.Count -eq 0){exit}else{foreach ($exefile in $foldercontents){Start-Process $exefile /q -wait}}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s