FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!

Powershell - connecting to a ConfigMgr Site




This basically does the same as clicking on 'file' in the configMgr admin console.

a lot of times I need to fetch data from the SCCM server and other locations such as Active Directory or a file server.



Code:
<#
   
    Author: Marcuzzo
    Description: Run this script on a server that has the configuration manager
                 console installed.
                 this script will load the CMDLets and will set the location to
                 the site.
                 for more information on the available CmdLets...
                 see: https://technet.microsoft.com/en-us/library/jj821831.aspx
                 
    Date: 13/05/2015
    Usage: powershell -NoExit -File Connect-CMSite.ps1

#>

# Check the environment variable set by the configuration manager console
if ( $Env:SMS_ADMIN_UI_PATH -eq $null )
{
    throw "Env not found"
    exit
}
else
{
    #import the ConfigMgr Module
    ipmo -Name "$(split-path $Env:SMS_ADMIN_UI_PATH)\ConfigurationManager.psd1"
}

# try to get the site name
$Site = ( gdr -PSProvider CMSite -ErrorAction SilentlyContinue );

# make sure that the site is valid
if ( ! ( $site ))
{
    Throw "CMSite provider not found"   
}


# Write-Host "Connecting to: $Site"
Set-Location "$($Site.Name):"

$CMSite =  ( Get-CMSite ).SiteName
Write-Verbose -Message "`n`tWelcome to $CMSite `n"



Adding this code in my script will allow me to connect to the site and use the ConfigMgr CmdLets



0 blog comments below




FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.