Monthly Archives: February 2015

Dot Sourcing variable and functions in Powershell

What I sometimes have trouble with is dot sourcing the ps1 files.  Dot sourcing a file allows the variables and functions to be available after the script has run.

A simple demo of this is to create a .ps1 file containing the following:
$a=dir

We then run this .ps1 file within powershell.  When we then try to use the variable $a, nothing happens, as the variable is removed when the script finishes.

To dot Source the file, use the command:
. .Test-DotSourcing.ps1
Notice the dot space dot backslash syntax.

The variable $a is now available within that session.

To use Dot sourcing with a function, consider the following function:

function test-DotSourcing2 {
    dir
}

We can use this by firstly Dot sourcing the .ps1 file as normal, then calling the function name directly (remove the .ps1 extension). 

The function name will also be available in tab completion.

Modify Send As Permission Exchange 2010

Open Exchange Management Console

 

Click Yes on the User Account Control Dialog if it appears

On the left hand side of the screen, navigate to Microsoft Exchange -> Microsoft Exchange On-Premises -> Recipient Configuration

 

Select Mailbox


Right click on the users mailbox you wish to send on behalf, and select Manage Send As Permission…

Click Add…

 

Select the name of the user you wish to give access to, and click OK
 

Click Manage
 

Click Finish   You can also accomplish this by using Powershell.  In this example, Andrew will be given Send As permission on Craig’s mailbox:

Add-ADPermission Craig -User Andrew -ExtendedRights “Send As”

You can also use groups.  In the example below, the group called Sales Users will be given Send As
permission on Craig’s mailbox:

Add-ADPermission Craig -User “Sales Users” -ExtendedRights “Send 
As”

To removing Send As:

Remove-ADPermission Craig -User Andrew -ExtendedRights “Send As”

This will prompt for confirmation, and the confirmation warning is a bit counter intuitive:

Confirm
Are you sure you want to perform this action?
Removing Active Directory permission “Craig” for user “Andrew” with access rights “‘Send As'”.
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [?] Help (default is “Y”): y

This means that this will remove Andrew’s send as permission on Craig’s mailbox.

Uninstall Pokki for All Users

(Edit 24/02/15 – corrected registry location)

Lenovo were preinstalling a Start Menu replacement on Windows 8 called Pokki.  Uninstalling this works for a single user, but as soon as another user logs in, the application is reinstalled.  This is not listed as Metro application that can be uninstalled using remove-appxpackage or remove-appxprovisionedpackage, as listed here (new window).

To uninstall this for all future users (This will not delete it for any users that have already created profiles, they will need to be done individually – see the end for more details):

Go into Programs and Features, and uninstall it like any other application

Yes choose to uninstall

Go into the userspublic folder, and delete the pokki folder

You will need to show hidden files and folders (see here for instructions – new window), and go in to the usersdefaultappdatalocal folder, and delete the pokki folder

Open regedit as ad administrator, select HKEY_USERS, click the file menu and select Load Hive…
Navigate to usersdefault and select NTUSER.DAT

Give the hive a name, eg: pokkiDefault and click OK

Navigate to HKEY_USERSpokkiDefaultSoftware
Delete the POKKI key

Navigate to HKEY_USERSpokkiDefaultSoftwareMicrosoftWindowsCurrentVersionRun
Delete the Pokki string value

Select the HKEY_USERSpokkiDefault key, select the file menu, and Unload hive… and select yes.

This will not delete pokki from profiles that are already created.  You can however delete the pokki files from each user profile, and use the regedit method above to load the other users hive and remove it from their startup.  I haven’t tried it but would also look at removing it from their Programs and Features list via this method: http://support.microsoft.com/kb/247501 and also looking in their hive at the equivalent HKCU registry location.