Yearly Archives: 2017

Get a list of user and there Group Membership

This is how to get an CSV file, including user_SamAccountName;User_FullName;group1;group2;group3, etc

It posible to remove the comment before break, and then break the export after 5 user, to see that it function well.

It will first write it output at the ending of the script, so terminate it, will result in an empty file.

$user_count = 0
$output = ""
$OFS = "`r`n"
$users = Get-ADUser -Filter * -SearchBase "DC=dalbjerg,DC=local" | SELECT Name,samaccountname

foreach($user in $users) {
    #echo $user.SamAccountName
    $username = $user.SamAccountName
    $output += $username + ";" + $user.name + ";"
    $groups = Get-ADPrincipalGroupMembership $user.Samaccountname | select name
        foreach($group in $groups) {
            $output += $group.name + ";"
        }
    $output += $OFS
    $output += $OFS
    $user_count += 1
    if($user_count -eq 5) {
        #break
    }
}
Write-Output $output | out-file C:\temp\export.csv

 

Powershell: Copy IIS from a time range to a specific folder

I need to search for entry in logfiles between 3/8-2017 and 6/8-2017. So i make this powershell script to prevent search all IIS logfiles.

This script will copy all log files from the orginal IIS log path to a temp log directory, including the parent folder.

	$destination = "c:\temp\log\"
	$files = get-childitem "C:\inetpub\logs\LogFiles\" -Recurse | ? {$_.LastWriteTime -ge "08/02/2017" -and $_.LastWriteTime -le "08/06/2017"}
	Foreach($file in $files) {
		#Test to see if the file already exists in the destination. If not => Move/Copy/Action you want :D
		$directory = Split-Path (Split-Path $file.fullname -Parent) -Leaf
		new-item $destination"\"$directory -type directory
		Copy-Item -Path $file.fullname -Destination $destination"\"$directory

	}

Delete specific mail in Sophus Exim queu

To show the queue in sophus, from CLI type:

chroot /var/storage/chroot-smtp /bin/exim -bp

To delete a specific mail type

chroot /var/storage/chroot-smtp /bin/exim -Mrm {mailid}

example:

chroot /var/storage/chroot-smtp /bin/exim -Mrm 1daHZv-000EaR-0A

To see how many mails, there are in queue, you can type:

chroot /var/storage/chroot-smtp /bin/exim -bpc

Give access to calendar based on the user is member of the group.

If you need to give auser access to users calendar, based on if there are member of an group, this is the way.
Start Exchange Management Shell

$users = Get-ADGroupMember [groupname] | select -ExpandProperty name
foreach ($user in $users) {
    $Mailbox = Get-Mailbox $user
	#The Calendar, is name "Kalender" in danish
	add-MailboxFolderPermission -identity “$($Mailbox.Name):\kalender” -AccessRights Editor -User [username]
	set-MailboxFolderPermission -identity “$($Mailbox.Name):\kalender” -AccessRights Editor -User [username]

	#English calendar
	add-MailboxFolderPermission -identity “$($Mailbox.Name):\calendar” -AccessRights Editor -User [username]
	set-MailboxFolderPermission -identity “$($Mailbox.Name):\calendar” -AccessRights Editor -User [username]
} 

New Equallogic warning mail: Free space is below threshold of 15 percent for pool PoolName. Default Snapshot Schedule will run with max-keep set to 1

After an upgrade of our Equallogic SAN to version 8 or later, i get this warning everyday:
Free space is below threshold of 15 percent for pool PoolName. Default Snapshot Schedule will run with max-keep set to 1.

I have 5% left on my SAN, and dosen’t used Snapshot at all on it. It only contain backup data. No needs to take snapshot of Backup data :).
So i turn of this warning message by SSH to the Grp Management IP, and logon with username, grpadmin and my password for this account.

After login I run this command: grpparams default-snapshot-sched disable

This will disabled the schedule running at 00:00, that checks for this 15% free space left.

Install Linux OSCore OS – With static network address

When you start the Linux OS – OSCore, from the bootable ISO file, you will just the a prompt.
To Install it, i following these steps

First we needed to be root

sudo su

Then we setup the IP address of the server

ip addr add 192.168.1.1/24 dev eth0
ip link set dev eth0 up
ip route add default via 192.168.1.254

Then we set the root password, and create a user

passwd
useradd itadmin
passwd itadmin

Then you ssh to the CoreOS server.

Then we need to setup the DNS settings

su
cd /etc
rm resolv.conf
vim resolv.conf

Type these into resolv.conf

nameserver 8.8.8.8
nameserver 8.8.4.4

We now need to setup the cloud-config-yaml file

cd /home/core/
vim cloud-config.yaml

Change the settings below so it fit you

#cloud-config
hostname: CoreOS_Name01
users:
- name: "YOURUSERNAME"
groups:
- "sudo"
- "docker"
ssh_authorized_keys:
- ssh-rsa YORESSSH-RSAKEY [email protected]
coreos:
units:
- name: static.network
content: |
[Match]
Name=eth0
[Network]
Address=192.168.1.1/24
Gateway=192.168.1.254
DNS=8.8.8.8
DNS=8.8.4.4

Then we just need to installed the CoreOS

coreos-install -d /dev/sda -C stable -c cloud-config.yaml
shutdown -h now

Remember after you have installed CoreOS, the username and password, and aslo the root password, will be lost.
You need to set this up in the Cloud-config file, if you for some reason will like static password after.

Unmount the CDROM from the server
Start the server again

Usefull things, about CoreOS, after you have installed it

cloud-config is located in /var/lib/coreos-install/user_data

if you need Boot Core os, with autologin. (If you for some reason can’t access the server though network).
Reboot the server, and press “e” in grup (Bootmenu) to edit the first boot option.
At the end of the line that begins with “linux$” add ” coreos.autologin=tty1″ (no quotes).
Press CTRL-X or F10 to boot. You will be logged in as “core” when the system boots.
And use sudo to become root