Thursday, June 26, 2014

Simplify your PowerShell and remember | is your friend

I had a colleague last week who wanted to clean up in his web application for site collection that he did not use. He google and found this piece PoweShell.

1 $tmpRoot = Get-SpWebApplication -Identity http://w520-sp2013-1:81
2 $tmpRootColl=$tmpRoot.Sites
3 for ($index=$tmpRootColl.Count-1 ; $index-ge 0 ; $index--) {Remove-SPSite -Identity $tmpRootColl.Item($index) -GradualDelete -Confirm:$false}
It now works fine too, but he had a hard time reading it and it could easily be made more simple. Eg. this way.


1 Get-SpWebApplication -Identity http://w520-sp2013-1:81 | Get-SPSite -Limit:All | Remove-SPSite -GradualDelete -Confirm:$false
Now there's no loop or variable you must remember to instantiate.

Wednesday, June 11, 2014

“Run as Administrator” the easy way

We live in a world that is run via PowerShell and how often have you not forgot to run his PowerShell script as "run as administrator"? But there are a few tricks in Windows so that it become easy.

As you probably already, how to start a problem with administrative privileges by right-clicking on a program/shortcut and select "Run as Administrator".
clip_image001

But did you know that by holding ctrl+shift down, you can obtain the same?

You can either double-click on a program/​​shortcut while holding ctrl+shift down or hit enter, it is the same.

Another trick is to make a shortcut to your program. Because on a shortcut, you can choose whether it always should "run as administrator"

How do you know about a problem running under the administrator context?

Look up at the program title bar. It says "Administrator" if it is running under sub-administrator context. This works not only for PowerShell command prompt but also for e.g. visual studio.

Untitled3