Get all users from specific Organizational Unit in an Active Directory

Ever found yourself in need of collection all users in a specific OU, filter for a given set of properties and export the list to a file? If yes, this script is for you!

$Users = Get-ADUser -SearchBase "OU=Sub-OU,OU=Parent-OU,DC=domain,DC=tld" -Filter * -Properties * | Select-Object SamAccountName,DisplayName,GivenName,Surname,whenCreated,Enabled,accountExpires,lastLogonTimestamp,LockedOut
$OUUsers = @()
$OUUsers += "SamAccountName,DisplayName,GivenName,Surname,whenCreated,Enabled,accountExpires,lastLogonTimestamp,LockedOut"
foreach ($User in $Users) {
    if ($User.accountExpires  -eq "9223372036854775807") {
        $OUUsers += "$($User.SamAccountName),$($User.DisplayName),$($User.GivenName),$($User.Surname),$(($User.whenCreated).ToString('yyyy-MM-ddZhh-mm-ss')),$($User.Enabled),$("Never"),$([datetime]::FromFileTime($User.lastLogonTimestamp).ToString('yyyy-MM-ddZhh-mm-ss')),$($User.LockedOut)"
    }
    if (-not($User.accountExpires  -eq "9223372036854775807")) {
        $OUUsers += "$($User.SamAccountName),$($User.DisplayName),$($User.GivenName),$($User.Surname),$(($User.whenCreated).ToString('yyyy-MM-ddZhh-mm-ss')),$($User.Enabled),$([datetime]::FromFileTime($User.accountExpires).ToString('yyyy-MM-ddZhh-mm-ss')),$([datetime]::FromFileTime($User.lastLogonTimestamp).ToString('yyyy-MM-ddZhh-mm-ss')),$($User.LockedOut)"
    }
}
$OUUsers | Out-File C:\tmp\OUUser-Report.csv

The script will search in domain.domain.tld\Parent-OU\Sub-OU and will select all users in this sub-OU. Here, it will collect the properties SamAccountName, DisplayName, GivenName, SurName, whenCreated, Enabled, accountExpires, lastLogonTimestamp and LockedOut. These properties will then be exported to the file OUUser-Report.csv which will be stored in C:\tmp.

Useful logfiles in Windows

The following tables contains a list of useful log file paths on a Windows client.

Application or servicePathDescription
Internet Explorer 7%windir%\ie7.log
%windir%\ie7_main.log
Only applicable to IE7. Deprecated.
Internet Explorer 8%windir%\ie8.log
%windir%\ie_main.log
Only applicable to IE8. Deprecated.
Internet Explorer 9%windir%\ie9_main.logOnly applicable to IE9. Deprecated.
Windows Update Log%windir%\WindowsUpdate.logOnly applicable to Windows versions up to and including 8.1. Deprecated.
SFC-log / CBS-log%windir%\logs\cbs\cbs.log
SECedit-log%windir%\security\logs\scesrv.log
Service Pack logC:\svcpack.log
msinfo32msinfo32 /report %userprofile%\desktop\msinfo32.txtExports the results from msinfo32 to a file and places it on the desktop of the current user.

Corrupted file permissions on Microsoft Windows

From time to time you might find yourself having troubles with file permissions in a Windows environment. This issue will show itself in you not being able to edit, change, move or delete one or multiple files on your computer. This can happen if the ownership settings of the file(s) are corrupted which happen once in a while. To recover the file permissions we are going to use two tools native to Windows; takeown and cacls.

The way to recover the file permissions are to do the following:

  1. Right-click the Start button and press Windows Powershell (Administrator)
  2. Execute the command takeown /f <full path to file> e.g., takeown /f C:\Windows\WindowsUpdate.log
  3. This will transfer ownership from whichever user- or system account to the account executing the command. However, ownership does not necessarily grant access to deleting the file.
  4. To reset this permission set, execute the command cacls <full path to file> /G <Username>:F e.g., cacls C:\Windows\WindowsUpdate.log /G Morten:F
  5. You have now effectively transferred ownership permissions to your account.

To read the full list of operators and parameters for the commands, please refer to the official Microsoft documentation for cacls and takeown.

How to change keymap on RaspBMC to fit MCE remote

How to change keymap on RaspBMC to fit the Microsoft MCE remote

  1. Connect to RPi using Putty or other SSH-client
  2. Copy the default XBMC keymap file to your home directory.
    cp /opt/xbmc-bcm/xbmc-bin/share/xbmc/system/keymaps/remote.xml /home/pi/.xbmc/userdata/keymaps/remote.xml
  3. I use nano to edit the remote.xml file. Use whatever editor you want.
    sudo nano /home/pi/.xbmc/userdata/keymaps/remote.xml
  4. In the global-section I edited the command of the yellow button to show the context menu.
  5. Default is:
    <yellow>XBMC.ActivateWindow(MyMusic)</yellow>
    New value is:
    <yellow>ContextMenu</yellow>
  6. Hit CTRL+X, Press Y to confirm and Enter to execute. Now changes are saved to the file.
  7. Restart your RaspBMC for the changes to take effect. In my case I needed to change the command of the yellow button but you can change whatever parameter that you need. You can find the full list of commands here.
“”;s:7:””summary””;s:0:””””;s:6:””format””;s:13:””filtered_html””;s:10:””safe_value””;s:1248:””

How to change keymap on RaspBMC to fit the Microsoft MCE remote

  1. Connect to RPi using Putty or other SSH-client
  2. Copy the default XBMC keymap file to your home directory.

    cp /opt/xbmc-bcm/xbmc-bin/share/xbmc/system/keymaps/remote.xml /home/pi/.xbmc/userdata/keymaps/remote.xml

  3. I use nano to edit the remote.xml file. Use whatever editor you want.

    sudo nano /home/pi/.xbmc/userdata/keymaps/remote.xml

  4. In the global-section I edited the command of the yellow button to show the context menu.
  5. Default is:

    <yellow>XBMC.ActivateWindow(MyMusic)</yellow>

    New value is:

    <yellow>ContextMenu</yellow>

  6. Hit CTRL+X, Press Y to confirm and Enter to execute. Now changes are saved to the file.
  7. Restart your RaspBMC for the changes to take effect. In my case I needed to change the command of the yellow button but you can change whatever parameter that you need. You can find the full list of commands here.

Windows shortcuts

CPL system shortcuts

CPL system shortcuts
ShortcutDescription
access.cplAccessibility controls
appwiz.cplAdd/remove programs
desk.cplScreen settings
hdwwiz.cplAdd/remove hardware
inetcpl.cplInternet Explorer settings
intl.cplRegional and international settings
joy.cplGaming settings
main.cplMouse settings
main.cpl,@1Keyboard settings
mmsys.cplSound settings
ncpa.cplNetwork Connections
nusrmgr.cplUser management
powercfg.cplPower management
sysdm.cplSystem Settings
telephon.cplPhone and modem settings
timedate.cplTime and Date settings
CPL system shortcuts

MSC system shortcuts
ShortcutDescription
ciadv.mscIndexing service
compmgmt.mscComputer Management
devmgmt.mscDevice Management
dfrg.mscDisk Defragtmentation Management
diskmgmt.mscDisk Management
gpedit.mscGroup Policy Management
services.mscWindows Services Management
eventvwr.mscEvent Viewer
MSC system shortcuts

Other shortcuts
ShortcutDescription
msinfo32System Information
msconfigSystem Configuration utility
dxdiagDirectX diagnostics
psr.exeProblem Steps Recorder
Other shortcuts