September, 2013

  • TechEd Australia 2013 - PowerShell for ConfigMgr 2012 SP1 - Demo 2

    Demo 2: Connecting via PowerShell

    Importing the ConfigMgr module

    Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'

    Connect to Primary Site (where PRI is the site code)

    Set-Location PRI:\

    Display all Configuration Manager cmdlets

    Get-Command -Module ConfigurationManager

    Display a count of all the Configuration Manager cmdlets

    (Get-Command -Module ConfigurationManager).Count

  • TechEd Australia 2013 - PowerShell for ConfigMgr 2012 SP1 - Demo 4

     Demo 4: Packages

    Automatically create Package from source directory, create Deployment Type, create Collection and Deployment

    $ErrorActionPreference = "Stop"
    Set-Location C:\
    $NewPackageLocation = "\\TECHED13\NewPackages\*"
    $CorpSourcelocation = "\\TECHED13\Source$\Packages"
    $NewPackageLocation = Get-Item $NewPackageLocation
    Copy-Item $NewPackageLocation -Destination $CorpSourcelocation -Recurse
    Remove-Item $NewPackageLocation -Recurse
    $PackageSourcePath = $CorpSourcelocation + '\' + $NewPackageLocation.Name
    $SplitValues = $NewPackageLocation.Name.Split("-")
    $PackageManufacturer = $SplitValues[0]
    $PackageName = $SplitValues[1]
    $PackageVersion = $SplitValues[2]
    $PackageLanguage = $SplitValues[3]
    Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'
    Set-Location PRI:\
    New-CMPackage -Path $PackageSourcePath -Name $PackageName -Manufacturer $PackageManufacturer -Version $PackageVersion -Language $PackageLanguage -Description "Created Using PowerShell"
    New-CMProgram -PackageName $PackageName -StandardProgramName "Setup $PackageName" -CommandLine "msiexec /i setup.msi /q"
    Start-CMContentDistribution -PackageName $PackageName -DistributionPointGroupName "All DPs"
    New-CMDeviceCollection -Name "Install -  $PackageManufacturer$PackageName$PackageLanguage$PackageVersion" -LimitingCollectionName "All Systems"
    Start-CMPackageDeployment -PackageName $PackageName -StandardProgramName "Setup $PackageName" -CollectionName "Install -  $PackageManufacturer$PackageName$PackageLanguage$PackageVersion" -DeployPurpose Available

  • TechEd Australia 2013 - PowerShell for ConfigMgr 2012 SP1 - Demo 3

     Demo 3: Collections

    Creating a single Collection

    New-CMDeviceCollection -LimitingCollectionName "All Systems" -Name "All Computers in 10.10.10.0" -RefreshType ConstantUpdate

    Creating a Collection Query Membership Rule for the above Collection

    Add-CMDeviceCollectionQueryMembershipRule -CollectionName "All Computers in 10.10.10.0" -QueryExpression "Select * from SMS_R_System where SMS_R_System.IPSubnets like '10.10.10.0'" -RuleName "10.10.10.0 Subnet Query"

    Source CSV file automated Collection creation

    NewMelbourneDCSubnets.csv (rename the file to NewMelbourneDCSubnets.csv)

    Script creating Collections based on CSV file

    $CSVSubnets = Import-Csv -Path .\NewMelbourneDCSubnets.csv
    Set-Location PRI:\
    ForEach($Collection in $CSVSubnets)
    {
    New-CMDeviceCollection -LimitingCollectionName "All Systems" -Name $Collection.SubnetName -RefreshType Constantupdate
    Add-CMDeviceCollectionQueryMembershipRule -CollectionName $Collection.SubnetName -QueryExpression "Select * from SMS_R_System where SMS_R_System.IPSubnets like '$($Collection.Subnet)'" -RuleName "$($Collection.Subnet) Subnet Query"
    }

  • TechEd Australia 2013 - PowerShell for ConfigMgr 2012 SP1 Content

    image

    Update: here is the video of my session (link below for full resolution video)

    http://channel9.msdn.com/Events/TechEd/Australia/2013/WCL416 


    Hello ConfigMgrDogs community.

    I’ve just completed my TechEd 2013 presentation – PowerShell for ConfigMgr 2012 SP1. For those who weren’t attending the event, I’ve provided all scripts and cmdlets from the session.

    In the coming weeks there will also be the video posted.

    Demo 1 – PowerShell Basics

    http://aka.ms/Bf7b7c

    Demo 2 – Connecting to ConfigMgr

    http://aka.ms/Pb6sbx

    Demo 3 – Collections

    http://aka.ms/Xq09ps

    Demo 4 – Apps and Packages

    http://aka.ms/Khmrnv

    Demo 5 – Application Approval

    http://aka.ms/Sr6m82

    Demo 6 – Five Demos in Five Minutes

    http://aka.ms/Esmluw

  • TechEd Australia 2013 - PowerShell for ConfigMgr 2012 SP1 - Demo 5

     Demo 5: App Approvals

    Script for System Tray notification, pop-up form and Approve/Deny an Application Approval Request

    Add-Type -AssemblyName System.Windows.Forms
    Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'
    Set-Location PRI:\
    $ApprovalRequests = Get-CMApprovalRequest | Where{$_.CurrentState -eq 1}
    ForEach ($Approval in $ApprovalRequests)
    {
    function Popup-Form

    param ($form)
                      
        $form.ShowDialog()    
    }
    $RequestUser = $Approval.User.TrimStart("CONTOSO\")
    $RequestApp = $Approval.Application

    $container = New-Object System.ComponentModel.Container
    $notifyIcon = New-Object System.Windows.Forms.NotifyIcon($container)
    $notifyIcon.Icon = New-Object System.Drawing.Icon("C:\Scripts\Demo 5\tick.ico")
    $notifyIcon.Text = "New App Approval Request Available"
    $notifyIcon.Visible = $true
    $notifyIcon.BalloonTipText = "New App Approval Request Available"

    $formImage = [System.Drawing.Image]::FromFile("C:\Scripts\Demo 5\background.jpg")
    $form = New-Object System.Windows.Forms.Form
    $form.Add_Shown({$form.Activate()})
    $form.Size = New-Object System.Drawing.Point(325,200)
    $form.StartPosition = "Manual"
    $form.Text = "New App Approval Request"
    $form.BackgroundImage = $formImage
    $screenBounds = [system.Windows.Forms.Screen]::Getworkingarea(0)
    $form.Location = New-Object System.Drawing.Point( (($screenBounds.right) - ($form.Width)),(($screenBounds.Bottom) - ($form.height)) )
    $form.FormBorderStyle = "fixedDialog"

    $label = New-Object System.Windows.Forms.Label
    $label.Text = "$RequestUser has requested the $RequestApp application"
    $label.Location = New-Object System.Drawing.Point(10,20)
    $label.MaximumSize = New-Object System.Drawing.Size(300,100)
    $label.Font = New-Object System.Drawing.Font("Segoe UI",11,[system.drawing.fontstyle]::regular)
    $label.Autosize = $true
    $label.BackColor = "Transparent"
    $form.Controls.Add($label)

    $buttonApprove = New-Object System.Windows.Forms.Button
    $buttonApprove.Text = "Approve"
    $buttonApprove.Size = New-Object System.Drawing.Size(120,50)
    $buttonApprove.Location = New-Object System.Drawing.Point(35,110)

    $buttonApprove.Add_Click(
    {
    # Approve Request
    Set-Location PRI:\
    Approve-CMApprovalRequest -Id $Approval.CI_UniqueID -Comment "Approved via PowerShell Form"
    $form.close()
    $notifyIcon.Visible = $false
    New-Event ClickComplete
    })
    $form.Controls.Add($buttonApprove)

    $buttonDeny = New-Object System.Windows.Forms.Button
    $buttonDeny.Text = "Deny"
    $buttonDeny.Size = New-Object System.Drawing.Size(120,50)
    $buttonDeny.Location = New-Object System.Drawing.Point(165,110)

    $buttonDeny.Add_Click(
    {
    # Deny Request
    Set-Location PRI:\
    Deny-CMApprovalRequest -Id $Approval.CI_UniqueID -Comment "Denied via PowerShell Form"
    $form.close()
    $notifyIcon.Visible = $false
    New-Event ClickComplete
    })
    $form.Controls.Add($buttonDeny)

    $notifyIcon.ShowBalloonTip(3)
    Register-ObjectEvent -InputObject $notifyIcon -EventName BalloontipClicked -Action {Popup-Form -form $form} | Out-Null
    Register-ObjectEvent -InputObject $notifyIcon -EventName MouseClick -Action {Popup-Form -form $form} | Out-Null
    Wait-Event -SourceIdentifier ClickComplete | Out-Null
    Remove-Event -SourceIdentifier ClickComplete | Out-Null
    }

    VBScript to launch the PowerShell script silently

    command = "%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe -NoLogo -WindowStyle Hidden -File C:\Scripts\Sched\Demo5_Complete.ps1"
    set shell = CreateObject("WScript.Shell")
    shell.Run command,2

     

    Files required to run the script

    background.jpg (rename to background.jpg)

    tick.ico (rename to tick.ico)

  • TechEd Australia 2013 - PowerShell for ConfigMgr 2012 SP1 - Demo 1

     Demo 1: Three Minute Intro to PowerShell

    Display all Bluetooth services

    Get-Service –DisplayName “*Bluetooth*”

    Store all services into a variable

    $AllServices = Get-Service

    Display a count of all the systems services

    $AllServices.Count

    Display a count of all the Bluetooth services

    $BluetoothServices = Get-Service –DisplayName “*Bluetooth*”
    $BluetoothServices.Count

    Stop all Bluetooth services

    $BluetoothServices | Stop-Service

    Start all Bluetooth services

    $BluetoothServices | Start-Services

  • TechEd Australia 2013 - PowerShell for ConfigMgr 2012 SP1 - Demo 6

     Demo 6: Five Demos in Five Minutes

    List the drivers in a given Boot Image

    $BootImage = $(Get-CMBootImage -Id "PRI00005").ReferencedDrivers
    ForEach($Driver in $BootImage)
    {Get-CMDriver | Where{$_.ContentSourcePath -eq $Driver.SourcePath} | Select LocalizedDisplayName

    List all Collections with Incremental Collection Updates enabled

    Get-CMDeviceCollection | Where{$_.RefreshType -eq 6} | Select Name

    Clear Required PXE Deployments for a Collection

    Clear-CMPxeDeployment -DeviceCollectionId "PRI0010E"

    Export Boundaries to a CSV file

    Get-CMBoundary | Select DisplayName,Value,SiteSystems | Export-Csv -LiteralPath C:\Temp\Boundaries.csv

    Lock an Application

    Lock-CMObject -InputParameter $(Get-CMApplication -Name "Demo App 1")