A PowerShell script shows how to create a Shutdown, Restart or Logoff Windows 8 tile for the Start menu.


Script source and documentation can be downloaded from here
A PowerShell script shows how to create a Shutdown, Restart or Logoff Windows 8 tile for the Start menu.


Script source and documentation can be downloaded from here
Being interested in computer history, now and then I look at old recordings and found Bill Gates announcing the Touch Sensitive Surface 21 years before Steve Ballmer made the announcement in 2012.
Bill Gates mentions “Surface” near 2.22 mins.
Let’s assume you’ve just created a larger number of packages within SCCM 2012 and then you’re asked to move the package sources to a different location. I guess no-one on earth would want to visit each package and update the data source manually, So I wrote 2 scripts that automate this task. It could actually be done with one script, but when it comes to changing such things I prefer to validate things.
As you can see from the screen shot below, we have 2 packages, with their Source Folder pointing to \\labsccm01\sources\Packages\App1 and \\labsccm01\sources\Packages\App2
Now we want to change the Source path from \\labsccm01\sources\Packages\App1 to \\labsccm01\sources\NewPackages\App1 and \\labsccm01\sources\Packages\App2 to \\labsccm01\sources\NewPackages\App2
The script does not move the actual content, so before running the scripts below, the source must be copied to the new location.
First we are going to look for packages that have their content stored under \\labsccm01\sources\Packages by running the following PowerShell script.
Note: Before running the below script make sure you’re connected to the site through PowerShell. Also make sure to set the variable $OldPath1 according to your environment.
# Define output file
$script_parent = Split-Path -Parent $MyInvocation.MyCommand.Definition
$csv_path = $script_parent + "\Update_Package_SrcPath_input.txt"
# Define data source path to search for
$OldPath1 = "\\LABSCCM01\Sources\Packages"
# Search and export packages
Get-CMPackage | Select-object Name, PkgSourcePath, PackageID | Where-Object {$_.PkgSourcePath.ToLower().contains($OldPath1.ToLower())} | Export-Csv $csv_path -Encoding Unicode -NoTypeInformation -delimiter "`t"
}
The output generated looks as following.
If we are sure that these are the packages we want to change, we copy paste the content and store into a new file called Update_Package_SrcPath.txt. Then open CMPackage_Update_SourcePath.ps1 containing the code below. Edit the variables $OldPath, $OldPath1 and $NewPath. If you just want to simulate things, add –whatif to the line that starts with Set-CMPackage
<#
.SYNOPSIS
Script to change the Package Data Source Folder path
.DESCRIPTION
Script to change the Package Data Source Folder path
This script allows you to change the server + Share path of the package source path.
for example when you created the packages first on \\server1\packagesource$\
and you want to move the content to \\server2\packages$\
.PARAMETER (none)
update the variables below
.NOTES
Author: Alex Verboon
Version: 1.0
- initial version
.EXAMPLE
#>
# ----------------------------------------------------------------------------------------------------*
# Variables
# ----------------------------------------------------------------------------------------------------*
# Specify the Source Path and the new Target path.
# Make sure to specify both OldPath and OldPath1
# Old Path - double the backslashes and add \ before $ signs so that the regular expression works...not nice but works
$OldPath = "\\\\labsccm01\\sources\\Packages"
# old path
$OldPath1 = "\\labsccm01\sources\Packages"
# New Path
$NewPath = "\\labsccm01\sources\NewPackages"
# ----------------------------------------------------------------------------------------------------*
# The Code
# ----------------------------------------------------------------------------------------------------*
# Get the input file
$script_parent = Split-Path -Parent $MyInvocation.MyCommand.Definition
$csv_path = $script_parent + "\Update_Package_SrcPath.txt"
$csv_import = Import-Csv $csv_path -delimiter "`t"
# Process all Package names in input file
ForEach ($item In $csv_import)
{
Write-host "Processing: " $item.Name
# Check if Package with "Name" exists
$a = Get-CMPackage | Where-Object {$_.Name -eq ($item.Name.Trim())}
If ($a.Length -ne 0 )
{
#Package exists, now check if the Package has a source path defined
$b = $a.PkgSourcePath
If ($b.Length -ne 0 )
{
#Write-host "Source Path currently set to :" $b -ForegroundColor Green
if ($b.Tolower().Contains($OldPath1.ToLower()))
{
$c = $b -ireplace $OldPath, $NewPath
Write-host "Updating path: " -foregroundcolor White -Nonewline; write-host $b -foregroundcolor green -nonewline; Write-host " to " -foregroundcolor White -NoNewline; write-host $c -ForegroundColor Green
# to only simulate what is going to happen, but not actually changing anything, just add -WhatIf to the next line
Set-CMPackage -Name $a.Name -Path $c
}
Else
{
write-host "Current path: " -ForegroundColor Yellow -NoNewline; write-host $b -ForegroundColor green -NoNewline; write-host " not matching with current path " -ForegroundColor White -NoNewline; write-host $OldPath1 -ForegroundColor Green -NoNewline; write-host " No action required!" -ForegroundColor Yellow
}
}
Else
{
Write-host "Package" $item.Name " has no Source Path set. No action required" -ForegroundColor Yellow
}
}
Else
{
Write-host "Package not found" -ForegroundColor Red
}
}
Write-host "Completed" -ForegroundColor blue
}
Going back to the Console we see the updated Source folders.
To make documenting the configured SCCM Client configuration settings a bit easier I wrote a small script that retrieves all the configured settings for the Default and custom configuration settings.
To run this script the Configuration Manager powershell module must be loaded and connected to the site.
# Get the different Client settings Names
$a = Get-CMClientSetting | select Name
foreach ($a in $a )
{
# Get all possible values for the Get-CMClientSetting -Setting parameter
$xsettings = [Enum]::GetNames( [Microsoft.ConfigurationManagement.Cmdlets.ClientSettings.Commands.SettingType])
# dump the detailed configuration settings
foreach ($xsettings in $xsettings ) {
#write-host $a.Name
Get-CMClientSetting -Setting $xsettings -Name $a.Name | format-table
}
}
While preparing for an SCCM 2012 upgrade, I thought it might be a good idea to consider implementing some of the best practices that are around such as integrating the DaRT Remote Connection tool into the OSD deployment process. I’m sure it comes in handy when having to troubleshoot OSD related tings, as it allows us to access the client remotely without having to give lengthy instructions to an onsite engineer.
I know others have written about this before, but it appeared to me that most content relates to MDT or SCCM 2007, so I thought it’s worth writing down an update for those using the latest Dart 8.x version and SCCM 2012 SP1. Nevertheless the following blog posts served as great input for what is described below.
Software Assurance Pays Off – Remote Connection to WinPE during MDT/SCCM deployments by johan arwidmark
Remote Connection to WinPE during SCCM deployments – creating shortcuts with Ticket numbers and IP on a file share by Alexey Semibratov
MDT 2012 New Feature: DaRT integration by Michael Niehaus
Note that the DaRT Remote Connection tool is part of the Microsoft Diagnostics and Recovery Toolset, a core component of the Microsoft Desktop Optimization Pack (MDOP) available for customers with Software Assurance.
1. Install DaRT 8.0 SP1. The installation MSI can be found on the MDOP installation media. (\DaRT\Installers\x64)
2. When installed you will find a Toolsx86.cab and Toolsx64.cab file located in the "C:\Program Files\Microsoft DaRT 8\v8\” directory.
3. Create the following folder structure that you can access later when preparing the boot image in SCCM.
..\PreStart_x64\CM12Dart\Windows\System32
The below screen shot shows the structure I have in my lab.
4. Extract the following files from the CAB file. (note that I use the 64 Bit version of the CAB file)
FirewallExceptionChange.dll
LockingHooks.dll
mfc100u.dll
MSDartCmn.dll
msvcp100.dll
msvcr100.dll
RdpCore.dll
rdpencom.dll
RemoteRecovery.exe
WaitForConnection.exe
and copy them all into the previously created .\PreStart_x64\CM12Dart\Windows\System32 folder. If you have no tools available to extract the files from the CAB file you can get them later in the process when we generate the DartConfig.dat file in step 7.
5. Next download the StartRemoteRecovery.zip created by Alexey Semibratov from here. From the archive file extract
StartRemoteRecovery.wsf
ZTIUtility.vbs
and copy them as well into the previously created System32 folder. Use the ZTIUtility.vbs provided. Replacing it with a newer one with cause the script to fail.
6. Since the script was originally written for DaRT 7, the line (124) containing the path to the DaRT Remote Viewer Tool must be updated.Replace the path with ""C:\Program Files\Microsoft DaRT 8\v8\DartRemoteViewer.exe" as shown below.
In order to easily identify the created shortcut we add the following code which creates the OSD environment variable DartShortCut
‘ create a variable that represents the shortcut name
oEnvironment.Item("DaRTShortCut") = oEnvironment.Item("ShortCutShare") & "\" & sShortcutName & ".lnk"
I haven’t had time for this yet, but the plan is to add a step to the Task Sequence to remove the link, so that our share doesn’t get filled with outdated connection links. I’ve therefore already created the variable.
7. Since on some networks not just all ports are open we are going to use a static port. e.g. 3388. Unfortunately this information is stored in a file called DartConfig.dat that can only be generated using the DaRT Recovery Image wizard that we have installed in step 1.
On the next page just select Next. Then select “Allow remote connections” and “specify the port number”
Skip through the following Wizard pages until you get here. Select “Edit Image”.
Now wait while the DaRT image is generated. (This can take a while). Then select “Open in Windows Explorer”
From the System32 folder copy the DartConfig.DAT and copy it into the ..\PreStart_x64\CM12Dart\Windows\System32 folder. If you did not extract the files from the CAB file in Step 4, you find them here as well. When done close the Explorer.
Going back to the wizard you can either select Cancel or Create.
8. Then create a batch file called PRESTART.CMD with the following content and copy that file into the .\PreStart_x64\CM12Dart folder
@echo off
XCOPY CM12DART X:\ /y /s
CSCRIPT X:\Windows\System32\StartRemoteRecovery.wsf /ShortCutShare:<\\servername\share> /UserID:<username> /UserDomain:<domain> /UserPassword:<password>
If you do not have a general purpose share in place yet, create one. I used the following:
\\labsccm01\Dart_Remote
9. Open the configuration manager console and open the Software Library Node. To not make this blog post too lengthy I am just going to assume that you’re familiar with creating a new or updating an existing boot image. Otherwise follow the steps described here.
Within the Image properties select the “Customization” tab. Select “Enable prestart command”. Then within the command line add:
cmd.exe /c PRESTART.CMD
Select “Include files for the prestart command” and navigate to the .\PreStart_x64 folder
Then Click “Apply” to save the changes.
Now that we have put everything in place, let’s start the OS Deployment Task Sequence. I am using SCCM boot media here, so I have booted my VM with SCCM Boot media that I have previously created.
As soon as we hit “Next” the prestart command kicks in and launches the DaRT Remote Connection tool, that sits minimized in the corner of the screen.
Now heading over to the Server where I have installed the DaRT Remote Viewer Tool and open the Share where the shortcut link is automatically created by the StartRemoteRecovery.wsf script.
and there you go, we now have a remote connection into our OS Deployment session.
Note that as soon as the client starts into Windows we loose the ability to use the DaRT remote connection tool
Any comments are welcome.