Use powershell to ping and output to log file

Copy following in a batch file, and you could ping multiple address at once and logged it to files:

start powershell.exe -Command "ping -t 8.8.8.8 | ForEach {'{0} - {1}' -f (Get-Date),$_} >> C:\Logs\Dot8.log"
start powershell.exe -Command "ping -t 10.0.0.1 | ForEach {'{0} - {1}' -f (Get-Date),$_} >> C:\Logs\GW.log"
start powershell.exe -Command "ping -t 10.0.0.60 | ForEach {'{0} - {1}' -f (Get-Date),$_} >> C:\Logs\DC.log"

 

Launch another process with Encrypted Credential (Powershell)

First create an AES key and output it to a file. (reference here)

$KeyFile = "C:\ps\s\AESKey\AES.key"
$Key = New-Object Byte[] 16   # You can use 16, 24, or 32 for AES
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key)
$Key | out-file $KeyFile

 
Second, use the AES key we created in the first step to encrypt the password and output it to a file.

$PasswordFile = "C:\ps\s\AESKey\pwd.txt"
$KeyFile = "C:\ps\s\AESKey\AES.key"
$Key = Get-Content $KeyFile
$Password = "Y0urS3curePa$$w0rd." | ConvertTo-SecureString -AsPlainText -Force
$Password | ConvertFrom-SecureString -key $Key | Out-File $PasswordFile

 
Now, you got a password file which can only be decrypted by that Key you created in first step.

Here is a snippet on how to create a powershell encrypted credential, and use it to launch another process.

# use the passwordfile, and key created earlier
$MyCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key)

# Lauch another process with other credential from the user's powershell session
# This is useful if the user only has normal right, and you could launch it with another credential whom has admin right.
Start-Process powershell.exe -Credential $MyCredential -WindowStyle Hidden -ArgumentList "Start-Process $($Program) -Wait -ErrorAction SilentlyContinue"

 

Please take step to protect that keyfile!

SSL installation for Apache on Windows

1. Export the new cert from MMC
- Choose export the private key
- Choose export include all certificates in certificate path if possible.
- Save the .pfx in location you selected.

2. On Apache server.
- Copy the new .pfx to this server
- in CMD, cd C:\Apache24\bin\
- openssl pkcs12 -in .pfx -nocerts -out private.key
- openssl pkcs12 -in .pfx -nokeys -out certificate.crt

* if there is PEM Pass Phrase (private.key), remove it by:
openssl rsa -in private.key -out private2.key

3. Update/Configure following as requires:
- extra\httpd-ssl.conf
- extra\httpd-vhosts.conf

* SSLCertificateFile "${SRVROOT}/conf/certificate.crt"
* SSLCertificateKeyFile "${SRVROOT}/conf/private.key"

4. Restart Apache service, done.

Cisco Catalyst - Trunk Configuration

Here are steps to set port to trunk mode:

1. After connected to switch with console
2. Enter configuration mode
Switch> enable
Switch# Configure terminal

3. Clear the port to default
Switch(config)# default interface gigabitEthernet 1/0/24

4. Set the port to trunk
Switch(config)# interface gigabitEthernet 1/0/24
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport trunk native vlan 1
Switch(config-if)# exit

5. Save settings
Switch# copy running-config startup-config

Password Recovery for Cisco Catalyst Switches

Steps to reset password for Cisco Catalyst Switches:

1. Connect PC with console cable
2. Unplug the power cable to the switch
3. Reconnect the power to the switch. Press and hold the Mode button while System LED is flashing green. After System LED turns amber and then solid green, release the Mode button.

If process followed correctly, the following message should be displayed:

flash_init
load_helper
boot

4.Enter these commands into the switch

Switch: flash_init
Switch: load_helper
Switch: dir flash:
Switch: rename flash:config.text flash:config.text.old
Switch: boot

5. Once the switch boot, answer NO to “Would you like to enter initial/system configuration dialog? [yes/no]:

6. Get into the privilege prompt
Switch> enable

7. Get into global configuration
Switch# conf t
Switch(config)# enable secret y0urPa$$word
Or,
Switch(config)# username admin privilege 15 secret y0urPa$$word

8. Save config
Switch(config)# exit
Switch# copy run start
Switch# reload