background preloader

PowerShell Code Repository

PowerShell Code Repository

WSUS Admin Module Verificado nas seguintes plataformas Este script foi testado nessas plataformas pelo autor. É muito provável que funcione nessas plataformas também. Se você tentar e ver que funciona em uma outra plataforma, adicione uma nota no script de discussãote para que os demais saibam. Suporte de colegas online Para obter suporte de colegas online, ingresse no The Official Scripting Guys Forum! Aviso de isenção de responsabilidade Não existe suporte para os script de exemplo em nenhum programa ou serviço de suporte padrão da Microsoft.

Resources and Q&A for PowerShell People Windows CMD Commands Get-AD Verified on the following platforms This script is tested on these platforms by the author. It is likely to work on other platforms as well. If you try it and find that it works on another platform, please add a note to the script discussion to let others know. Online peer support For online peer support, join The Official Scripting Guys Forum! Disclaimer The sample scripts are not supported under any Microsoft standard support program or service. PowerShell Magazine Pearltrees Export and Import PowerShell ISE Opened Files - Windows PowerShell Blog Unlike other tools, PowerShell ISE doesn’t have project files. Project files are a good way to set your environment up with a well known state. Thanks to the ISE Object Model, it is possible to add some project functionality. The script below has two main functions “Export-ISEState” and “Import-ISEState”. Even script contents for untitled files are saved. To save the current state (state = files and PowerShellTabs), use something like: Export-ISEState c:\temp\files.isexml To load the state later run: Import-ISEState c:\temp\files.isexml When exporting the current state the all titled files are saved with the script from my last post. For untitled files, the contents are saved. If you like it, you can add it to your profile (psedit $profile will edit the ISE profile) or to a module imported in your profile. Lucio Silveira [MSFT] function Save-AllISEFiles Saves all ISE Files except for untitled files. foreach($tab in $psISE.PowerShellTabs) foreach($file in $tab.Files) if(! $file.Save() Param # File 1:

ISESteroids – A Revolutionary PowerShell ISE Add-On If you love the built-in ISE editor that ships with PowerShell 3.0 and 4.0, but you were missing some professional editor capabilities, then ISESteroids add them for you. It is a commercial PowerShell module that seamlessly integrates with the ISE editor, written by PowerShell MVP Tobias Weltner (me). The primary goal of ISESteroids was to keep the beautiful simple UI, and not turn the editor into something as complex as the control panel of a nuclear power plant. Let me take you on a quick walk-through! (Click on a screenshot to view larger image) Installation ISESteroids are no separate application. Simply get yourself a trial copy here: Once you unpacked the .zip file, you get a folder called “ISESteroids”. Loading ISESteroids To launch ISESteroids, start the PowerShell ISE editor, then enter this: Visual Helpers ISESteroids adds green and blue squiggle lines. Click on a squiggle to find out about the problem in the ISE status bar.

LESS « The Dynamic Stylesheet language Importing and Exporting Credentials in PowerShell – Precision Computing One question that comes up fairly often when dealing with (or writing!) secure cmdlets is how to properly handle usernames and passwords. The solution there is to use (or make) the -Credential parameter of type PSCredential. A PSCredential object helps ensure that your password stays protected in memory, unlike cmdlets that accept a straight username / password combination. If a parameter is of type PSCredential, PowerShell supports several types of input: empty: If you supply no input to a mandatory -Credential parameter, PowerShell prompts you for the username and password.string: If you supply a string to the -Credential parameter, PowerShell treats it as a username and prompts you for the password.credential: If you supply a credential object to the -Credential parameter, PowerShell accepts it as-is. This is great for interactive use, but what if you want to write an automated script for a cmdlet that accepts a -Credential parameter? Problem Solution “CachedUser“,$password Discussion

Lee Holmes -dot- Com PylonsHQ - Home Emit-XML - Windows PowerShell Blog I was writing a demo yesterday and needed a quick and dirty way to generate some XML so I wrote the function below. This highlights a couple of changes that are coming up in CTP3 that I thought I would preview. 1) The keyword "cmdlet" is going away and we'll just have "function". The first Here-String starts the XML document with a "<Object>". function Emit-XML{Param ([Parameter(Mandatory=$true, ValueFromPipeline=$true)]$object) @"<Object>$( foreach ($p in $object |Get-Member -type *Property) { $Name = $p.Name $Value = $Object. Here is an usage example: PS> gsv alg | Emit-xml<Object> <Name>ALG</Name> <CanPauseAndContinue>False</CanPauseAndContinue> <CanShutdown>False</CanShutdown> <CanStop>False</CanStop> <Container></Container> <DependentServices></DependentServices> <DisplayName>Application Layer Gateway Service</DisplayName> <MachineName>. I have to admit - I am VERY excited by some of the stuff we are lined up to deliver to you in V2.

Richard Siddaway's Blog Saw a post about WmiMonitorID that intrigued me If you use the WmiMonitorID: PS> Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorID | select -f 1 You get a number of properties returned as an array of numbers. if you look at the property with Get-CimClass they unsigned 16 bit integers Name : ManufacturerName Value : CimType : UInt16Array Flags : Property, ReadOnly, NullValue Qualifiers : {MAX, read, WmiDataId} ReferenceClassName : Probably the easiest way to deal with them is a very simple function and calculated fields function Convert-ArrayToName { param ($array) ($array | foreach { [char][byte]$_} ) -join '' The function Convert-ArrayToName accepts an array. Call the function in a calculated field to convert the numeric array to a string – repeat for all relevant properties. Run the code and becomes Active : True Manufacturer : GSM ProductCode : 598F SerialNumber : 304NDJX51788 UserFriendlyName : 22EA63 WeekOfManufacture : 4 YearOfManufacture : 2013

Related: