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…

PowerShell Uninstall Automation

I have authored the PowerShell Uninstall script.  It gives the ability for IT Operations / ConfigMgr Admins to uninstall multiple versions of a particular software with one process.

Does your organization struggle when trying to cleanup software when standardizing on a application version? I.E. Oracle Java, Adobe Flash, RightFax, IBM products, etc…  Not all the versions you have are in ConfigMgr / SCCM or not in the application model?  If the answer is yes, the PowerShell Uninstall script is for you.

The PowerShell Uninstall script takes inputs from a CSV file.  Using the delimiter of “^”, don’t worry I have included a Excel file to build your CSV.

Since by nature when uninstalling legacy software there maybe pre-or post- process you must run. The PowerShell Uninstall script has functions to call a PowerShell script before or after the uninstall logic.

The PowerShell Uninstall script also includes a Boolean to  create the script as an ConfigMgr / SCCM Application.  In which you can attach to other programs for requirements.

To detect the PowerShell Uninstall script, have ConfigMgr / SCCM check existence of “%SystemDrive%\Program Files\Pomeroy\AppName”.  It will be an empty directory.  For the uninstall just use the command “rmdir /Q /S %SystemDrive%\Program Files\Pomeroy\AppName”

Continue reading…

SCCM 2012 Folder Creation Script

I have created a script that will automate SCCM 2012 folder creation.  Either in bulk or single by single. It is a simple script with no parameters.  You just run the script and follow the instructions.  If you want to bulk folder create the text file must be in the format where the folder names is per line.

Example.

folder name 1
folder name 2
folder name 3
folder name 4
…..

Here is a walk through.

Get Help:

Get-Help.

Single Folder Creation:

Single folder creation.

Bulk Folder Creation:

Bulk folder creation.

Click the download link to give it a try.

CM2012 Node Folder Creation v2.0

 

Randomize Local Administrator Password

I created this tool to randomize local administrator passwords.

This application takes two strings and creates a calculated and complex password based on the input.   Now the local administrator’s password will be unique to each computer.

Here it is at screen launch:


A. The organization’s asset identification string.
B. The organization’s custom identification number.  Up to 10 digits long.
C. The selected password length for added complexity.
D. After all input is entered the user generates the complex password.
E. The result of the calculation.

Result:

The best part of this application is also supports it being used in the console.  This gives the application the ability to be scripted during an OSD build, deployed enterprise wide, or required update. Below is the console help menu and a PowerShell script I wrote to automate the process.  This is included in the *.zip file.

Enterprise Help Desk Dynamic Admin – Version 1.0.0.1

 

System Center 2012: PowerShell – Connecting to Configuration Manager

From over on the TechNet blogs, explains the PowerShell connection with System Center 2012

Welcome to installment #2. In case you missed installment #1 – Getting Started – here’s the link. With the Getting Started blog, you tried a few basic Windows PowerShell cmdlets. I hope you took a bit of time to explore what other cmdlets are available in Windows. But now it’s time to get Configuration Manager hooked up to your PowerShell environment. Let’s start with the easy method………

Read the full post over on the “System Center Configuration Manager Team’s Blog Site”……

http://blogs.technet.com/b/configmgrteam/archive/2013/03/27/powershell-connecting-to-configuration-manager.aspx

SCCM Admin Tools

I have created a new tool, SCCM Admin Tools, using the new SAPIEN PowerShell Studio 2012.This tool will become more robust, but for right now all you can do is remotely start / stop / or check status of the SMSEXECUTIVE and WDSServer services on your SCCM sites.

You will be able to save the settings for the site server’s name and site code.  You will want to use your central site if you have one.  Or the top most primary.

Here are some screenshots:

 

You can download the executable from here.  Get in touch with me if you have any other suggestions. Once I get the application to a certain goal I will release the source files.

SCCM Admin Tools v1.3.2.1

Snow Land’s SCCM-Commands

I have had the privilege of getting my hands on the SAPIEN PowerShell Studio 2012.  Using SCCM-Commands on the backend is so easy.  As a SCCM Administrator I have mostly focused right now on making my life easier on the job.  Cutting all the unnecessary process I need to do manually.  So if you are an SCCM Administrator and you love you some PowerShell than check this link out.

http://www.snowland.se/sccm-posh/

This is a great module.

Find AD Stale Computers

Active Directory Stale Computer Report

I have created a nice PowerShell script to find your stale computer objects in Active Directory. With being a SCCM Administrator it is crucial you have a healthy AD environment.

Requirements:

Quest Active Directory CMDLET
http://www.quest.com/powershell/activeroles-server.asp

Usage:

.AD_StaleComputer_Cleanup.ps1 -DC “Domain Controller” -Old “PC Not logged in for X amount days” -Path “Path of the folder you want the report saved too”

Example:

.AD_StaleComputer_Cleanup.ps1 -DC “DCServer01” -Old 90 -Path “C:PathofFolder”

 

AD_StaleComputer_Cleanup.ps1 v1.0.0.1