PowerShell

PowerShell Logging – The Basics

PowerShell Logging will be the best thing you learn.  The biggest topic I get asked for help outside the specific activities I am assigned to is PowerShell.    I will be the first to understand everyone has their own style.  I never judge the style or syntax format.  Besides that, PowerShell logging ALWAYS needs to occur.  If you are not logging, your running blind. PowerShell logging is the one the most powerful features you can learn and implement.  

PowerShell does have some native abilities, “Start-Transcript“, and if that is all you want to understand, that is fine.   But, this post will take you through some basic understandings on capturing your outputs in a format that is readable and standard.  With some tricks in creating some great logic around managing your log.

PowerShell Logging – The Setup

The first step into your new logging endeavors is to understand the ability to call a function to simplify your process. 

For this function to become usable we first must set the variable “$logpath” so the function can understand where it is writing to.   My standard is to log to “%SystemDrive%\Windows\Temp”

# Set log path
$logpath = "$env:SystemDrive\Windows\Temp\mynewlog.log"

# Function to write to log file
function Write-Log
{
	param($msg)
	"$(Get-Date -Format G) : $msg" | Out-File -FilePath $logpath -Append -Force
}

Calling the Function

During your process of creating your script you will want to call the PowerShell logging function to say your going to run a process, log the process file call, its arguments, other module calls, and most important capturing any error output. 

Write-Log "Running:"
Write-Log "setup.exe -S -v/l "$env:SystemDrive\Windows\Temp\Setup.log"

Continue reading…

Introducing: PowerShell Gallery

The wonderful PowerShell folks announced a great new PowerShell feature called gallery that is coming in 5.0

Introducing the PowerShell Gallery – PowerShellGet is an exciting new feature releasing in WMF 5.0 Preview.  With it, you can easily discover, install, update, and publish PowerShell modules to and from online repositories – simplifying the process of sharing PowerShell content.

Find out all the details over here:

http://blogs.msdn.com/b/powershell/archive/2014/11/19/powershell-gallery-live.aspx

 

PowerShell DSC Resource Kit Wave 9

Over on the “Windows PowerShell Blog” they announced the release of PowerShell DSC Resource Kit Wave 9.

Head over to the blog to read all about it:

Here’s a holiday gift from the PowerShell team – the DSC Resource Kit wave 9. You can find it right here.

This wave has something for everyone, we hope. There are 34 new DSC resources across 13 modules! We have also incorporated your feedback, and made fixes to several existing resources that address issues you have encountered.

Last year we delivered the first DSC Resource Kit as a holiday gift, with 11 DSC resources. In case you are counting, we now have 172 DSC resources, enabling use of DSC for deploying and configuring Active Directory, Azure VMs, Certificate Services, SQL Server, DNS, file shares, Failover clusters, Internet Explorer, Exchange, web applications, Hyper-V, networking, Just Enough Administration, DNS, Remote Desktop Services, the System Center products (SCDPM, SCOM, SCSMA, SCSPF, SCSR, SCVMM), and more. In all, this is a great start in a single year, with more to come in 2015!

http://blogs.msdn.com/b/powershell/archive/2014/12/17/another-holiday-present-from-the-powershell-team-dsc-reskit-wave-9.aspx