Escape special characters inside folder/file name variable

array=(`find /path/ -mindepth 2 -maxdepth 2 -type d -print | sed -e ‘s;[^/]*/;;g’ |  sed ‘s/&/\\&/’`)

( sed ‘s/&/\\&/’  replaces & with \& in the folder/file name )

Posted in Linux | Tagged , | Leave a comment

Exchange – remove address from all groups and hide it from GAL

Filename:  script.ps1

$email = (read-host “email”)

$GG = Get-DistributionGroup
$RG = $GG  | where {(Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains “$email”}

foreach( $dg in $RG ){
Remove-DistributionGroupMember $dg -Member $email
}

get-mailbox -Identity $email | Set-Mailbox -HiddenFromAddressListsEnabled $true

 

Posted in Exchange | Leave a comment

Expanding a LVM root partition to fill remaining drive space

Posted in Linux | Tagged | Leave a comment

Convert URL text to clickable hyperlink in Excel

1. Select the range of url text that you want to convert to clickable hyperlinks.

2. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. Click Insert > Module, and paste the following code in the Module Window.

1
2
3
4
5
6
7
8
9
10
11
12
Sub ConvertToHyperlinks()
'Updateby20140318
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    Application.ActiveSheet.Hyperlinks.Add Rng, Rng.Value
Next
End Sub

4. Then press F5 key to run the code, a pop up dialog for you to select a range, then click OK, and the selected unlinked urls have been converted to the clickable hyperlinks.

Posted in Windows | Tagged | Leave a comment

Resize KVM guest disk space then resize PV LV

Increase KVM virtual machine guest’s disk space from the command line if you initially set insufficient amount of disk space:

  1. Shutdown the VM
  2. Move the current image
    mv mykvm.img mykvm.img.bak
  3. Create a new image
    qemu-img create -f raw addon.raw 30G
  4. concatenate the 2 images
    cat mykvm.img.bak addon.raw >> mykvm.img
  5. Alternatively – use qemu-img to reize a qcow2 image: qemu-img resize my-server.qcow2 +10GB 
  6. start the VM (using the newly created mykvm.img)
  7. run fdisk inside VM and delete & re-create LVM partition
    % fdisk /dev/vda
    ...
    Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *           1          13      104391   83  Linux
    /dev/vda2              14        3263    26105625   8e  Linux LVM
     
    Command (m for help): d
    Partition number (1-4): 2
     
    Command (m for help): p
    
    Disk /dev/vda: 48.3 GB, 48318382080 bytes
    255 heads, 63 sectors/track, 5874 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
     
    Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *           1          13      104391   83  Linux
     
    Command (m for help): n 
    Command action
      e   extended
      p   primary partition (1-4)
    p
    Partition number (1-4): 2
    First cylinder (14-5874, default 14): 14
    Last cylinder or +size or +sizeM or +sizeK (14-5874, default 5874): 
    Using default value 5874
     
    Command (m for help): p
     
    Disk /dev/vda: 48.3 GB, 48318382080 bytes
    255 heads, 63 sectors/track, 5874 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
     
    Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *           1          13      104391   83  Linux
    /dev/vda2              14        5874    47078482+  83  Linux
     
    Command (m for help): t
    Partition number (1-4): 2
    Hex code (type L to list codes): 8e
    Changed system type of partition 2 to 8e (Linux LVM)
     
    Command (m for help): p
     
    Disk /dev/vda: 48.3 GB, 48318382080 bytes
    255 heads, 63 sectors/track, 5874 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
     
    Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *           1          13      104391   83  Linux
    /dev/vda2              14        5874    47078482+  8e  Linux LVM
     
    Command (m for help): w
    The partition table has been altered!
     
    Calling ioctl() to re-read partition table.
     
    WARNING: Re-reading the partition table failed with error 16: Device or 
    resource busy.
    The kernel still uses the old table.
    The new table will be used at the next reboot.
    Syncing disks.
    %
  8. Reboot the VM
  9. Resize the LVM physical volume
    % pvdisplay 
      --- Physical volume ---
      PV Name               /dev/vda2
      VG Name               VolGroup00
      PV Size               24.90 GB / not usable 21.59 MB
      Allocatable           yes (but full)
      PE Size (KByte)       32768
      Total PE              796
      Free PE               0
      ...
     
    % pvresize /dev/vda2
     
    % pvdisplay
      --- Physical volume ---
      PV Name               /dev/vda2
      VG Name               VolGroup00
      PV Size               44.90 GB / not usable 22.89 MB
      Allocatable           yes 
      PE Size (KByte)       32768
      Total PE              1436
      Free PE               640
      ...
  10. Resize the LVM Logical Volume
    % lvresize /dev/VolGroup00/LogVol00 -l +100%FREE
      Extending logical volume LogVol00 to 43.88 GB
      Logical volume LogVol00 successfully resized
  11. Grow the File system
    % resize2fs /dev/VolGroup00/LogVol00 
      resize2fs 1.39 (29-May-2006)
      Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
      Performing an on-line resize of /dev/VolGroup00/LogVol00 to 11501568 (4k) blocks.
      The filesystem on /dev/VolGroup00/LogVol00 is now 11501568 blocks long.

Tested on RHEL7.2 VM

Source: http://akyl.net/how-do-you-increase-kvm-guests-disk-space

 

Posted in Linux | Tagged , | Leave a comment

Linux Emergency Reboot / Shutdown

echo 1 > /proc/sys/kernel/sysrq  
echo b > /proc/sysrq-trigger

The first line is for enabling SysRq, and the second one is for rebooting.

More info HERE.

echo 0 > /proc/sysrq-trigger  if you need to shutdown instead of rebooting
Posted in Linux | Leave a comment

Force CentOS 6 to Re-Detect Network Devices

Edit the interface that “doesn’t seem to be present”:

vi /etc/sysconfig/network-scripts/ifcfg-eth0 and remove the HWADDR line.

Remove the old 70-persistnet-net.rules file: rm  /etc/udev/rules.d/70-persistent-net.rules

Removing this file will force udev to probe for network interfaces at boot and create a new 70-persistent-net.rules with the appropriate MAC address.

Reboot

Posted in Linux | Leave a comment

Exchange – Add mailbox permissions to Domain Admins

Add-MailboxPermission -Identity alice.cooper -User “Domain Admins” -AccessRights 
Fullaccess -InheritanceType all
Posted in Exchange | Leave a comment

Exchange – Check Email forwarding using Powershell

Get-Mailbox -Filter {ForwardingAddress -ne $null} | ft Name,ForwardingAddress,DeliverToMailboxAndForward -Autosize | Export-CSV e:\Email_forwarding_output.csv

Posted in Exchange | Leave a comment

Reset password in Active Directory using PowerShell

 

  • You must have the cmdlets ( part of the ActiveDirectory module for PowerShell v2 )
  • For Windows 7, you need to install the latest RSAT (Remote Server Admin Tools) and then add the Windows Feature for the PowerShell AD Module
  • PS C:\> Import-Module ActiveDirectory
  • $MyPass= ConvertTo-SecureStringStringSummer2014’ –AsPlainTextForce
  • Set-ADAccountPassword -Reset -NewPassword $MyPassIdentity alice.cooper
    Unlock-ADAccountIdentity alice.cooper   ( if the account is locked )
    Set-ADUserIdentity alice.cooperChangePasswordAtLogon $true  (if you want the user to change his pass at 1st log on )

Get-Command -Module ActiveDirectory  !!!   ( see the rest of the available commands  )

Posted in Exchange | Leave a comment