background preloader

PowerShell Code Repository

PowerShell Code Repository

Manipulation des fichiers en VBA - Club des décideurs et professionnels en Informatique VBA propose des méthodes pour travailler sur les fichiers. Ces fonctions de bases telles que Dir, Name, etc. ont un comportement proche des commandes DOS. Malheureusement, elles sont beaucoup trop limitées et permettent, hélas, que très peu d'actions ou bien alors au prix d'un code lourd à maintenir. Afin d'étendre les possibilités en ce qui concerne la manipulation des fichiers et des répertoires, Microsoft à mis au point un ensemble d'objets regroupés au sein de la librairie Microsoft Scripting Runtime. Cet ensemble de classe hiérarchique possède une unique racine : le FileSystemObject, plus communément connu sous le nom de FSO. Bien qu'il s'agisse en fait du nom d'une classe, il n'est pas rare de voir le mot FSO désigner la technique d'accès aux fichiers dans sa globalité. La hiérarchie des objets de cette librairie peut être comparée à celle de l'explorateur Windows : des fichiers inclus dans des dossiers qui eux-mêmes sont inclus dans des disques. I-B-1. I-B-2. I-B-3. I-B-4. I-C-1.

Beyond Export-Csv: Export-Xls - LucD notes Warning: this post has no “virtual” content ! This time I post a function that allows you to export your data to a “real” spreadsheet (XLS format) instead of a CSV file. The reason for posting this function was a series of threads in the PowerCLI Community by Suresh. Over several threads he has been collecting scripts that create various reports on his vSphere environment. Ultimately he wanted to have a spreadsheet where each report would be stored on a worksheet. PowerShell has the very handy Export-Csv cmdlet to create CSV files but afaik nothing for creating XLS files That’s when I decided to “pimp” my XLS creating function I already had to something more suited for general use. The function uses Excel through a COM object. Update June 16th 2010: the function has a new parameter -ChartType which allows the addition of a chart on the worksheet. Update November 2nd 2010: a complete overhaul of the function The script Annotations Line 112-117: The function tests if the XLS file exists or not.

posh-git Speed Up Excel Automation with PowerShell - Hey, Scripting Guy! Blog Summary: Microsoft PFE, Georges Maheu, optimizes the Windows PowerShell script he presented yesterday. Microsoft Scripting Guy, Ed Wilson, is here. Our guest blogger today is Georges Maheu. Note: All of the files from today, in addition to files for the entire week are in a zip file in the Script Repository. Take it away Georges... Today, we look at scaling up yesterday’s script. The first version of the script was linear and simple but somewhat slow; it works well for a small to mid-size environment, but it does not scale well for larger environments. When doing security assessments, most of the time, only a subset of computers is considered. Unfortunately, I am not aware of profiler tools for Windows PowerShell. Another option is to use the Measure-Command cmdlet. After you instrument the original script, the following statistics are generated: WMI query: ~ 0.25 seconds for responding local computer WMI query: ~ 1.00 seconds for responding remote computer Ping dead computer: ~2.5 seconds

LucD notes - My PowerShell ramblings Top SharePoint Sites | SharePoint Branding Examples | Best SharePoint Design Examples | Free SharePoint Themes and Templates Custom objects default display in PowerShell 3.0 | Shay Levy April 13, 2012 In PowerShell 3.0 we can now create new custom objects using a hash table. PS> [PSCustomObject]@{ One = 1 Two = 2 Three = 3 Four = 4 Five = 5 } One : 1 Two : 2 Three : 3 Four : 4 Five : 5 Behind the scenes, PowerShell creates a hash table and wraps it a PSCustomObject. It is way faster than using the New-Object cmdlet and it also provides consistency, while maintaining backwards compatibility. Another benefit of using PSCustomObject over New-Object is property order. PS > [PSCustomObject]@{One=1;Two=2;Three=3} One Two Three --- --- ----- 1 2 3 PS > New-Object PSObject -Property @{One=1;Two=2;Three=3} One Three Two --- ----- --- 1 3 2 Notice that when the new PSCustomObject is returned, all of its properties are displayed in the console. We can also define the properties of the type that will be displayed by default with the formatting cmdlets.

Microsoft Exchange 2010 PowerShell Cookbook (Review) [easyazon-image align="left" asin="1849682461" locale="us" height="110" src=" width="89"]PowerShell is hands down one of the most important skills than an Exchange administrator can learn. You can do a lot in Exchange Server 2010 using the GUI administration tools, but eventually you’re going to have to drop into the shell to do some deeper administration or simply to save time on bulk admin. My first contact with PowerShell was when Exchange Server 2007 was released. Today I’m working on a team that manages an Exchange Server environment of over 80,000 mailboxes, so using PowerShell on a regular basis is pretty much mandatory. Well it looks like that book has finally arrived in Microsoft Exchange 2010 PowerShell Cookbook by Mike Pfeiffer. Mike is an Exchange MVP, a Microsoft Certified Master on Exchange 2010, and someone whose blog I’ve followed for quite a while now. PowerShell Key Concepts Summary

PowerShell One-Liners: Collections, Hashtables, Arrays and Strings The way to learn PowerShell is to browse and nibble, rather than to sit down to a formal five-course meal. In his continuing series on Powershell one-liners, Michael Sorens provides Fast Food for busy professionals who want results quickly and aren't too faddy. Part 3 has as its tasty confections Collections, Hashtables, arrays and strings. This series is in four parts: This is part 3 Notes on Using the Tables A command will typically use full names of cmdlets but the examples will often use aliases for brevity. Most tables contain either 3 or 4 columns: a description of an action; the generic command syntax to perform that action; an example invocation of that command; and optionally an output column showing the result of that example where feasible. For clarity, embedded newlines (`n) and embedded return/newline combinations (`r`n) are highlighted as shown. Many actions in PowerShell can be performed in more than one way. This is a multi-part series of PowerShell reference charts.

Harnessing PowerShell's String Comparison and List-Filtering Features "Hmm. Wifi Hotspot!" When you are first learning PowerShell, it often seems to be an 'Alice through the looking-glass' world. Just the simple process of comparing and selecting strings can seem strangely obtuse. PowerShell is an outstanding successor to the Windows/DOS batch language. The tradeoff for this added power and flexibility, though, is an increased complexity: learning PowerShell is not a trivial undertaking. Please imagine what it is like for anyone falling into this particular rabbit hole. "Funny, the doors are getting smaller, but the size of Windows keeps growing." It was all very well to say "Program with me," but the wise little Alice was not going to do that in a hurry. “Let’s try listing all the files in the current directory. Both of those sound like convenient aliases, Alice surmised. “So now”, she mused, “I know that … Get-ChildItem -exclude *.dll,*.exe … will answer the original question. I started out in Accountancy, but then discovered Lisp

Powershell: How to get get date-1 formatted mm-dd-yyyy? LDAP Query Basics Topic Last Modified: 2011-01-13 By William Taylor This article discusses Lightweight Directory Access Protocol (LDAP) queries, which can be useful, but confusing, when troubleshooting Microsoft® Exchange Server and its relationship to its directory. = (EQUAL TO) This LDAP argument means a certain attribute must be equal to a certain value to be true. While working with Exchange Server, you encounter situations that use LDAP strings. The following example illustrates how to search using Active Directory Users and Computers: Open Active Directory Users and Computers. This example attempts to find all objects that either have prez for their title or test for the start of their name. You can also search using LDP, which is included in Microsoft Windows Server™ 2003 and Windows® 2000 Server support tools. A dialog box appears that should have the correct value in the Base DN field. C:\>ldifde -d "DC=witaylorroot,DC=com" -f c:\output.txt -r "(&(objectClass=user)(mailNickName=jeff*))

Use Copy-Property to Make it Easier to Write, Read,and Review Scripts - Windows PowerShell Blog Dennis Verwiej is doing some great PowerShell work over at his blog Just PowerShell It at . Recently he posted a blog entry Import Citrix Published Application in which he Imports a CSV file (previously exported) and then calls a few APIs to recreate the published application. If you at the code (in the middle of this blog entry), it the vast bulk of it is a series of lines setting properties before calling the API. Why not leverage the special capabilities of PowerShell to make this problem go away? You have to deal with the situation of what to do if you try to set a property that doesn't exist. function Copy-Property ($From, $To, $PropertyName ="*"){ foreach ($p in Get-Member -In $From -MemberType Property -Name $propertyName) { trap { Add-Member -In $To -MemberType NoteProperty -Name $p.Name -Value $From. Leveraging this routine allows you to transform this code: into this: See how much easier that is to Write, Read and Review? Enjoy! Thanks James!

Search Users from Multiple Domains Using a Common Attribute–PowerShell Script ~ Santhosh Sivarajan's Blog This script searches 2 Active Directory domains using a common matching attribute value (employeeID) and creates an out file with Source SamAccountName, Target SamAccountName and Name. You can use this script if you are performing user migrations and merging user accounts during the migration. Input file – Empid.csv – contains all employee IDs. Output file – UserInfo.txt - The script generates a TAB delimited file output which contains Source SamAccountName, Target SamAccountName and Name files. In this script I am using employeeID as the common attribute to search user account in the source (ss-infra.lab) and target (santhosh.lab) domains. Download:

Related: