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
"$(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 "setup.exe -S -v/l "$env:SystemDrive\Windows\Temp\Setup.log"
Continue reading “PowerShell Logging – The Basics”
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 “PowerShell Uninstall Automation”
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:
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!
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.
folder name 1
folder name 2
folder name 3
folder name 4
Here is a walk through.
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
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.
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 126.96.36.199
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”……
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.
This is a great module.
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.
Quest Active Directory CMDLET
.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”
.AD_StaleComputer_Cleanup.ps1 -DC “DCServer01” -Old 90 -Path “C:PathofFolder”