[Powershell] How to zip multiple files using 7-Zip (with password protection)

Here's another note to self...

I've been looking for a way to password protect a csv file but found it's not possible natively so one way to encrypt it is to zip it first and password protect the zip file.

Now I have multiple files I want to to zip using 7-Zip compression and again I've been googling my brains out looking for the correct search terms and eventually landed on this answer so here's how I applied it to my Powershell script...

First make sure you have 7-Zip installed on your computer. Then take note of the 7z.exe file 

Note that this example is for static files or individual files you can specify directly. This is not for dynamic files or all files in a folder. I'll get to that in time hehe

Here's the code that creates a random password, defines the csv files to zip, and creates a password protected zip file by passing the filenames as arguments

## -- Creating Random Password -- ##

$randomPassword = [System.Web.Security.Membership]::GeneratePassword(8,2)

## -- Files to zip -- ##

$csvFile = "D:\csvFile1.csv"
$csvFile2 = "D:\csvFile2.csv"

## -- Creating Zip File -- ##

$zipOutputFilePath = "D:\ZipOutputFile.zip"
$pathTo64Bit7Zip = "C:\Program Files\7-Zip\7z.exe"
$arguments = "a -tzip ""$ZipOutputFilePath"" ""$csvFile"" ""$csvFile2"" -mx9 -p$randomPassword"
$windowStyle = "Normal"
$p = Start-Process $pathTo64Bit7Zip -ArgumentList $arguments -Wait -PassThru -WindowStyle $windowStyle
$zipped = $ZipOutputFilePath

After execution your zip file should ask for a password before extracting.

That's it! 


How to Setup IIS and PHP on Windows 10 Desktop

Basically I followed this step-by-step from Microsoft, but for my own sake I'm writing my own so it's easier to find.

Setup IIS from Windows Control Panel

  • Open Control Panel >> Programs >> Turn Windows features on or off
  • Select Internet Information Services >> Expand and check CGI under World Wide Web Services -- Application Development Features

  • Test by opening http://localhost/ on your browser

Download and Install PHP

  • Extract PHP zip files to C:\PHP
  • Extract WinCache zip files to C:\PHP\ext
  • Open Control Panel >> System and Security >> System >> Advanced System Settings
  • On System Properties >> Go to Advanced tab and add a C:\PHP System Variable under Environment Variables

  • Open IIS Manager >> Select your machine under connections >> Open Handler Mappings

  • Add Module Mapping with the following details:
    • Request path: *.php
    • Module: FastCgiModule
    • Executable: C:\PHP\php-cgi.exe (location of php-cgi.exe within your PHP folder)

  • Add Default Document by going to Default Document >> Add >> add default.php and index.php

  • Create a PHP Info page to test
    • Create a phpinfo.php file on Notepad++ (run as Admin) with the following code: 
      <?php phpinfo(); ?>  
      ... and save inside C:\inetpub\wwwroot\

  • Open http://localhost/phpinfo.php on your browser and you should see this page

End. :)

Hope this helps.


[UiPath] How to use variable as delay duration (convert String to TimeSpan)

Say you want to use a variable as delay duration instead of hardcoding the time span (ie. 00:00:05), how do you convert a string variable into a proper duration variable?

Duration field accepts values with data type TimeSpan.
To convert a String to TimeSpan, use...


...where delay is a string variable containing the delay duration in seconds. In this example, it's 10 seconds. 

That's it! Hope this helps! 


[UiPath, VB.net] How to split string into characters

I was looking for ways to split a string into characters and found this .net string method that works perfectly.

Say you want to split the word elephant into individual characters and display it, just use the method ToCharArray() and it will be converted the way you want it!

Take note to change the TypeArgument of the For Each loop to System.Char

Alternatively, you may also access each character in the string by its index number.

"elephant"(0) returns "e"
"elephant"(1) returns "l"
"elephant"(2) returns "e"
"elephant"(7) returns "t"

You get the drill!


How to install Active Directory on Windows 10

On your Desktop, Start >> Settings >> Apps >> Apps & Features >> Optional features >> Add feature

Look for RSAT: Active Directory Domain Services and Lightweight Directory Services Tool

If it tells you of any dependency, install that first. Here it shows I need to install RSAT: Server Manager first so let's do that

After installation you should have Active Directory apps installed on your machine

Hope this helps!


How to install UiPath extension on MS Edge

This is the easiest way for me. Since Microsoft Edge is Chromium-based, it supports the same extension used by your Google Chrome browser. 

So the UiPath Web Automation Chrome extension should work:

What you should do is open the extension URL and install it straight on your Edge browser. With this you don't need to install through UiPath studio or even the command line anymore. This is all you need.

Issues may arise if you're working within an oganization which blocks installation of unverified extensions. In such cases, you have to reach out to your Service Desk or Desktop Engineering team and get the clearance needed to have the extension whitelisted.

After installation, enable it on the browser and you should now be able to identify objects on MS Edge.

Hope his helps!


How to edit hosts file in Windows 10

 Might come in handy!

1. Run Notepad as Administrator (right click > Run as Admin)

2. Open the location C:\Windows\System32\Drivers\etc, select All Files and hosts should appear on the list

3. Add the IP and hostname on the last line then save. In this case I added two hosts for surfandperf and google. You may read the commented part for more details.

That's it! Test by checking your browser if the hostname works.