Powershell: Copying new and modified files only

By YellowOnline on Thursday 10 September 2015 14:45 - Comments (6)
Category: Powershell, Views: 4.273

Here's a quick function for people like me who work in environments without ROBOCOPY (yes, it's possible). Obviously this doesn't really compare to Robust File Copy, but it allows you to at least copy new and modified files only without dependencies.


PowerShell:
1
2
3
4
5
6
7
Function NotExactlyRobocopy ($SourceFolder, $TargetFolder)
    {
    $SourceFiles = @(Get-ChildItem -Path $SourceFolder)
    $TargetFiles = @(Get-ChildItem -Path $TargetFolder)
    $Update = Compare-Object $SourceFiles $TargetFiles -Property FullName, LastWriteTime, Length | Where-Object {$_.SideIndicator -EQ "<=" }
    $Update | ForEach-Object { Copy-Item -Path $_.Fullname -Destination $TargetFolder} 
    }



Disclaimer: Only tested with the -WhatIf switch that I removed from the code. Use at own risk.

It isn't recursive yet and doesn't take care of system files or hidden files, simply because I didn't need those when writing this. I'll make it better version tommorrow, but at least it gives you an idea of how to do it (adding parameters to Copy-Item isn't exactly hard).

The Basics of Powershell & Active Directory

By YellowOnline on Wednesday 12 August 2015 15:55 - Comments (2)
Category: Powershell, Views: 4.114

Three methods, all with their advantages and disadvantages, for reading, writing and creating new users in AD with PowerShell. For the examples, we're interested in two totally different attributes: DisplayName and Fax. We also include authentication to allow management in multi-domain forests.

Feel free to add your tips and/or corrections in the comment section.


PS. Yes indeed: the Powershell lexer is now available on the Tweakers forums and blogs :D

Read more »

Getting ESX VM paths with PowerCLI

By YellowOnline on Monday 13 July 2015 12:07 - Comments (0)
Category: Powershell, Views: 3.882

I see quite some people trying to figure out how to get the folder of a virtual machine with PowerCLI (basically, an ESX PoSh module) and most solutions I see involve complex constructions with Get-Folder. That's really not necessary: as you would expect, the VM Object contains this information. It's just a bit hidden


Read more »

Sneak preview: Tweakblogs Offline Editor nl

Door YellowOnline op zaterdag 1 juni 2013 14:36 - Reacties (11)
Categorie: Powershell, Views: 3.797

Onlangs schreef ik nog eens een post in de 'Taboes in Bed' serie, maar door een verkeerde handeling (per ongeluk Back geklikt in de browser) verloor ik 5 uur schrijfwerk (en Forward hielp helaas niet).

Gefrustreerd heb ik die post niet meer opnieuw geschreven - die zal moeten wachten tot ik nog eens zin heb om lang te schrijven en veel op te zoeken... .

Om dit soort dingen te voorkomen bedacht ik dat een offline editor wel handig zou zijn, waarin je een hoop extra functionaliteit kan steken. Vooral handig voor mensen zoals mij die met sommige posts de limieten van TweakBlogs opzoeken inzake lengte :)

Welnu: vandaag ben ik er aan begonnen in de minst voor de hand liggende taal mogelijk voor zoiets: Powershell. Inderdaad, ik maak een BB-code text editor in een scripting taal.


Lees verder »

BoxeeBox, IMDB & Powershell

By YellowOnline on Friday 3 May 2013 17:00 - Comments (13)
Category: Powershell, Views: 4.728

If I were better at home in electronics, I would make an interface to make coffee through Powershell. Well, and if I would drink coffee. I am probably the only IT professional who does not drink coffee.

Anyway: just to say that I use Powershell for pretty much everything I can use it for. Today: organizing my BoxeeBox media library.


Read more »