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.

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.

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:

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

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.

A Module to Create Modules and Advanced Functions - Windows PowerShell Blog [1/3/09 Update - the original link to the attachment containing this code was broken but is now fixed. Sorry. jps] It is hard to overstate how important Modules and Advanced Functions are. If you are a PowerShell user - you need to take the time to learn these new mechanisms and use them as your first choice in implementing new functions. Advanced Functions provide help, parameter tab-completion, and cmdlet semantics that make it easy for other people to use your functions. Modules make it easy to package functions and use them in ways that they don't collide with each other. The only downside of using Modules and Advanced Functions is that they both require extra work when you start writing code. PS> Import-Module Module PS> Get-Command -Module Module CommandType Name Definition ----------- ---- ---------- Function New-GUID ... Begin { }#Begin Process { Throw "Not Yet Implemented" }#Process End { }#End New-ModuleTemplate does something similar for Modules. Enjoy!

New-RDCManFile 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. 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. Validate SPN mappings 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.

Related: