Permanently setting Windows environment variables from scripts (e.g. PowerShell)

To permanently set Windows environment variables (e.g. PATH) from a (PowerShell) script, you can use setx or Set-ItemProperty like this (for the current user): setx VARIABLE value Set-ItemProperty -Path ‘Registry::HKEY_CURRENT_USER\Environment’ -Name VARIABLE -Value “value” And here is the result:

Weiterlesen…

PowerShell: Configure some basic Windows settings after a fresh installation

After installing Windows I always started configuring the same old basic settings: move Desktop, Documents, Music, Videos, Pictures folders to D:\ configure some basic settings in Windows Explorer folder options (e.g. show hidden files, show file extensions) remove Internet Explorer from taskbar and add PowerShell to it Today I set…

Weiterlesen…

PowerShell: Check whether a Windows command or executable is available

In one of my recent PowerShell scripts I needed to find out if certain commands (in my case “svn”, “git”, “ant” and “mvn”) were available or not. I wrote this small function that tries to call the given command and returns whether it is callable. function commandAvailable($cmd, $options) {  …

Weiterlesen…

PowerShell: How to read contents from text files without converting the lines into an array

Apparently, PowerShell’s get-content cmdlet automatically converts the contents of text files into an array of strings, splitting the contents at the line breaks (see Using the Get-Content Cmdlet). In many cases this is convenient: Contents of file test.txt: 1 2 3 gc text.txt | % { write-host “line: ” $_…

Weiterlesen…

Verweis auf mein PowerShell-Script in der aktuellen Ausgabe der hakin9

In der aktuellen Ausgabe der hakin9 verweist Hannes Schurig im Rahmen seines Artikels “Manuelle und automatisierte Administration einer Active Directory Domäne und Grundlagen der Gruppenrichtlinien” auf mein kleines PowerShell-Script zum Auslesen von Computern aus einem Active Directory. Danke für die Referenz! 🙂 Aber unabhängig von der kleinen Referenz hat Hannes…

Weiterlesen…

PowerShell: Read user’s groups from Active Directory

Here’s a short PowerShell function to retrieve a list of a user’s groups from Active Directory: function getADGroups($username) {   $root = ([adsi]"").distinguishedName;   $searcher = new-object System.DirectoryServices.DirectorySearcher($root);   $searcher.filter = "(&(objectClass=user)(sAMAccountName=$username))";   $user = $searcher.findall();     $groupNames = @();   if ($user.count -eq 1)   {    …

Weiterlesen…