NT Account to SID translation …. and back again.

  I keep the following nifty functions in my Powershell profile, it helps when working with SIDs and Active Directory, it allows you to easily convert a SID back to the NTACCOUNT and vice versa…   function ConvertTo-Sid ($NtAccount) {(new-object system.security.principal.NtAccount($NTaccount)).translate([system.security.principal.securityidentifier])} function ConvertTo-NtAccount ($sid) {(new-object system.security.principal.securityidentifier($sid)).translate([system.security.principal.ntaccount])}

0

Group Nesting Powershell report using Quest Activeroles

  I was recently asked to provide a report on the number (and depth) of nested groups in AD. Getting a list of the groups inside a group is pretty simple using get-qadgroupmember <groupname> -type group, however getting the groups inside that group (inside that group) requires some iteration, and can be a bit tricky…

5

Zipping files older than X days

  Recently I was working with a firewall that wrote some tremendously large log files and was eating disk at an alarming rate, so to remedy this, and sharpen my Powershell pencil, I decided to write a script that could be setup with task scheduler to zip up older logfiles….   The script requires the…

3

Powershell and Hyper-V Management

  There’s an awesome tool on codeplex for managing Hyper-V using Powershell called PSHyperV, it’s especially handy if you’re working with Hyper-V on a Windows Server Core installation. http://pshyperv.codeplex.com/ Just download the library, drop the folder into the $pshome\modules directory, type import-module HyperV at a Powershell prompt and away you go…   This module adds some…

0

Powershell Remote User Logoff / Reboot

When patching servers, any disconnected user sessions typically prevent the post-patch auto reboot. To remedy this you could use the following Powershell script :   foreach ($_ in get-content servers.txt) {(gwmi win32_operatingsystem -ComputerName $_).Win32Shutdown(4)}   The script uses an input file named servers.txt populated with the names of all the servers targeted by auto-patching GPOs to…

3

Merging and appending to CSV files using Powershell

The time-tested approach of appending data to the end of a file using >> doesn’t necessarily work with CSV files in Powershell, and Out-File with the -append switch typically results in a corrupted CSV file. Recently I wrote a Powershell script for a customer to poll GPO information on a periodic basis and write that…

0

Powershell – Deleting files X days old

Here’s a powershell script you can use to delete files in a directory (and all sub-directories) X days old or older.   $Now= Get-Date $Days = “3” $TargetFolder = “u:\backup” $LastWrite = $Now.AddDays(-$days) $Files = get-childitem $TargetFolder -include *.txt, *.log, *.bak -recurse | Where {$_.LastWriteTime -le “$LastWrite”} foreach ($File in $Files) {   write-host “Deleting…

0

Creating secondary proxy addresses

Often times it may become necessary to stamp an additional SMTP address (proxy address) on a user account, either as part of a migration, or organizational domain name change etc…   Here’s a VBScript example of how to add a new SMTP domain name to each user account in AD, preserving the user’s name (everything to…

1

Putting colorized Powershell code in your blog documentation

I love powershell, I love it’s power, flexibility and extensibility, however I I do most of my work in the shell because I cannot stand to use the ISE.   The only feature of the ISE that I like it is the way it changes the color of variables, cmdlets, parameters etc.. since it makes it…

0

First things first

My name is Darryl Kegg and I am a Senior Deployment Consultant at Microsoft, I am part of the Premier Deployment team within the America’s Cloud Services group deploying Office 365.   My background has been primarily focused on Exchange, Directory Services and Virtualization, with a minor in VOIP, telephony, Powershell, Lync, OCS and VMWare.    Q: So, why…

1