Powershell Sciprts in SCCM TS

I am working with SCCM 2012 using PowerShell scripts in the task sequence.
I want to be able to trigger a reboot and retry in the task sequence, and I think the code should pre pretty straight forward, but something is obviously wrong.
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
for ($i = 0; $i -lt 10; $i++){
write-output $i " - " $tsenv.value("SMSTSRebootRequested") | out-file -filepath "C:\TestVal.log" -append
write-output " <<<<<<<<<<<<<>>>>>>>>>>>>>> " | out-file -filepath "C:\TestVal.log" -append
$tsenv.value("SMSTSRebootRequested")=$true
$tsenv.value("SMSTSRetryRequested")=$true
When I run the code manualy (f8 then run the script) there are no errors, but when I run it as a task sequence I get a generic 2147500037 error number.
In the task sequence this is a run command and its command is 'powershell.exe -executionpolicy bypass -file "TS_Var.ps1"'

In my Task Sequence I use powershell for importing startlayout to Windows 8, so the step itself is run powershell step, not command line. I only have .ps script name typed and execution policy set to bypass in UI. The command in .ps file starts like
POWERSHELL-NonInteractive-CommandImport-StartLayout...
bla bla bla :)
Hope this helps.

Similar Messages

  • Creating powershell scripts using SCCM 2012 device properties

    I am trying to create a PowerShell script that will create a MAB object based on SCCM device properties. This MAB object is needed to reimage over our network.
    My goal is to create a task sequence that will utilize these properties and create the MAB object in our AD. This will be the first step in my Task Sequence. This will have to use the SCCM device MAC Addresses property information to populate a
    sAMAccount property in my AD object.
    Any suggestions on how to start this process?

    I am still working on actually getting the full process completed here. I have a script that completes the necessary task of creating an MAB object in our Active Directory. This works from a command line opened on the client machine. When I deploy the script
    in a Task Sequence it does not complete. Here is what I am deploying in my task sequence.
    %winDir%\System32\windowsPowershell\v1.0\powershell.exe -noprofile -command Set-ExecutionPolicy Bypass LocalMachine -force
    %winDir%\System32\windowsPowershell\v1.0\powershell.exe -noexit -command import-module ActiveDirectory -force;MABCreation.ps1 -force;Set-ExecutionPolicy RemoteSigned LocalMachine -force
    This errors at the import step everytime. I have created a batch file and used the command line option in the task sequence. I have also tried to Disable 64 bit file redirection option on and off. Any further suggestions?

  • Powershell–Schedule a SCCM Advertisement using powershell

    I need to change advertisement schedule every day.
    Advertisement Start Time
    Advertisement Expires
    Mandatory Assignments
    Example of what I need :
    Today the Advertisement has the following settings
    Advertisement Start Time – 4/20/2012  23:00.
    Advertisement Expires – 4/21/2012 06:00
    Mandatory Assignments – 4/20/2012 23:30
    Tomorrow the Advertisement will have the following settings
    Advertisement Start Time – 4/21/2012 23:00.
    Advertisement Expires – 4/22/2012 06:00
    Mandatory Assignments – 4/21/2012 23:30
    I get the script but I could n't change Mandatory assignment. When I run the script Mandatory assignment take advert start time.
    The output I get
    Today the Advertisement has the following settings
    Advertisement Start Time – 4/20/2012  23:00.
    Advertisement Expires – 4/21/2012 06:00
    Mandatory Assignments – 4/20/2012 23:00
    Tomorrow the Advertisement will have the following settings
    Advertisement Start Time – 4/21/2012 23:00.
    Advertisement Expires – 4/22/2012 06:00
    Mandatory Assignments – 4/21/2012 23:00
    Can you please help me to modify the Mandatory assignments..
    Below is my powershell script.
    Param([String[]] $AdvertisementID)
    $SCCM_SERVER = "[server name without the brackets]"
    $SCCM_SITECODE = "[three letter site code without brackets]"
    #$AdvertisementID = "[AdvertisementID without the brackets]"
    #Foreach ($AdvertisementID in $AdvertisementIDs)
    $AdvertisementSettings = ([WMIClass] "\\$SCCM_SERVER\root\SMS\site_$($SCCM_SITECODE):SMS_Advertisement").CreateInstance()
    $AdvertisementSettings.AdvertisementID = $AdvertisementID
    #Get lazy properties
    $AdvertisementSettings.Get()
    #Build the Scheduled Time
    # $NewDate = (Get-Date).adddays(1)
    $year = [string](Get-Date).Year
    $month = [String](Get-Date).Month
    if ($month.Length -eq 1) {$month = "0" + $month}
    $day = [string](Get-Date).Day
    if ($day.Length -eq 1) {$day = "0" + $day}
    $ScheduledTime = $year + $month + $day + "230000.000000+***"
    #Build the Expiration Time
    $ExpireDate = (Get-Date).AddDays(1)
    $day = [string]$ExpireDate.Day
    if ($day.Length -eq 1) {$day = "0" + $day}
    $ExpirationTime = $year + $month + $day + "060000.000000+***"
    #Apply the settings to the advertisement
    $AdvertisementSettings.PresentTime = $ScheduledTime
    $AdvertisementSettings.ExpirationTime = $ExpirationTime
    $AdvertisementSettings.ExpirationTimeEnabled = $true
    $AdvertisementSettings.put()
    $AssignedSchedule = ([WMIClass] "\\$SCCM_SERVER\root\SMS\site_$($SCCM_SITECODE):SMS_ST_NonRecurring").CreateInstance()
    $AssignedSchedule.StartTime = $ScheduledTime
    $AdvertisementSettings.AssignedSchedule = $AssignedSchedule
    $AdvertisementSettings.AssignedScheduleEnabled = $true
    $AdvertisementSettings.put()

    I haven't got a chance to test this but from what I see...I see what might be causing the issue.
    Can't say for sure until I test it but , you use put() to set the WMI instance twice in your last few lines.
    So the later put() method invocation might be having problems as WMI Instance has changed already:
    #Apply the settings to the advertisement
    $AdvertisementSettings.PresentTime = $ScheduledTime
    $AdvertisementSettings.ExpirationTime = $ExpirationTime
    $AdvertisementSettings.ExpirationTimeEnabled = $true
    #$AdvertisementSettings.put() Don't commit now
    $AssignedSchedule = ([WMIClass] "\\$SCCM_SERVER\root\SMS\site_$($SCCM_SITECODE):SMS_ST_NonRecurring").CreateInstance()
    $AssignedSchedule.StartTime = $ScheduledTime
    $AdvertisementSettings.AssignedSchedule = $AssignedSchedule
    $AdvertisementSettings.AssignedScheduleEnabled = $true
    $AdvertisementSettings.put()
    rest of the code looks good but I think this might be causing an issue. I will give it a shot in my lab later.
    Do you get any errors .....I don't see any error handling in your code too. So let me go back and try this.
    Hope this helps
    Knowledge is Power{Shell}
    DexterPOSH
    My Blog

  • Connect via Windows Powershell in SCCM 2012 CONSOLE (with PowerShell 4.0 installed)

    Hi,
    When trying to "Connect via Windows Powershell" in the SCCM 2012 console, I get the message that Powershell 3.0 is not installed... (which actually isn't installed, we have PS4.0 installed). Do we need to install PS3.0 also to get it working
    or is there a workaround? Connecting manually to the site via Powershell 4.0 (Get-Psdrive -psprovider CMSITE) works like a charm.
    Regards,
    WiM

    Hi,
    I have installed WMF 4.0 on Windows Server 2008 R2 sp1, it works fine.
    Please try to use "$PSVersionTable" to confirm Powershell version is 4.0. At first, I forgot to install Microsoft .NET Framework 4.5, then the console gave me the message that Powershell 3.0 is not installed.
    Best Regards,
    Joyce Li
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Why can't I run a powershell file I created from a powershell function

    Ok so admittedly I am still learning a lot about powershell so this may have a very easy explanation/solution
    So I have this script file and this is it in its entirety 
    function Add-DriveFunctions($Provider, $Path)
    foreach ($Drive in $Provider.Drives)
    if ((Get-Command | where Name -eq "$($Drive.Name):") -eq $null)
    [String]"function $($Drive.Name):() {Set-Location $($Drive.Name):}" | Out-File $Path -Append
    $Path = C:\Temp\test.ps1
    """Adding Drives""" | Out-File $Path
    foreach ($Provider in Get-PSProvider)
    Add-DriveFunctions -Provider $Provider -Path $Path
    C:\Temp\test.ps1
    When I run it it happily creates the ps1 file whose content looks like this
     "Adding drives"
    function Alias:() {Set-Location Alias:}
    function Env:() {Set-Location Env:}
    function Function:() {Set-Location Function:}
    function HKLM:() {Set-Location HKLM:}
    function HKCU:() {Set-Location HKCU:}
    function Variable:() {Set-Location Variable:}
    But the last line to actually load and run the ps1 file does nothing
    even calling C:\Temp\test.ps1 does nothing
    but if I load the file into ISE and run it from there
    it works.
    Unless I'm completely missing something I would think being able to call other ps1 files from other ps1 files or the command line would be a pretty important part of powershells flexibility.
    So if anyone could tell me why in this case it does not work I would greatly appreciate that
    Cheers,
    Quidquid latine dictum sit, altum videtur

    Ok i'm a little confused 
    in ISE if I write a ps1 file and i have just a function in it not anything calling that function when i run or debug it loads that functions definition into the current session and then from my console i can access my function. so Is that what the . is supposed
    to do?
    When i tried the . I get this
    The term '.C:\Temp\test.ps1' is not recognized as the name of a cmdlet, function, script file, or operable 
    program. Check the spelling of the name, or if a path was included, verify that the path is correct and try 
    again.At C:\Users\rjs012978\Downloads\FunctionTest.ps1:20 char:1
    + .C:\Temp\test.ps1
    + ~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (.C:\Temp\test.ps1:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    Also I know i can do that with the mono letter drive but working on a network over half the alphabet is taken up by my actual network mapped drives.
    And the provider i'm writing is connecting to multiple Space IDs that i'm making into my drives so I would quickly run out of letters.
    proof of concept i know what i'm doing works if I do it manually
    I know it's kind of silly but for me the amount of time i spend in powershell especially administering SCCM, the registry and AD being able to just type hklm: and hitting enter is a huge time save over the long haul than typing cd hklm: even though it's
    just 3 more characters
    Quidquid latine dictum sit, altum videtur

  • Determine whether a client is a member of SCCM 2007 or 2012

    Hi,
    I would like to use PowerShell to query sccm to determine whether or not a client(s) has been successfully migrated to our 2012 environment or not. Is this possible somehow to do this? And this output this list? Or maybe using AD? Is there a way to determine
    this?
    Thank you.

    Yes, I know this is an old post, but I’m trying to clean them up.
    What you are asking for is NOT a simple query, you will need to query both the CM07 and CM12 db. I estimate that this would take several hour to setup and create a basic report.
     As such this is not the type of thing that is easily answered within the forums. I suggest talking to your DBA or hire someone that can write the report and the details on how to do this type of thing.
    Garth Jones | My blogs: Enhansoft and
    Old Blog site | Twitter:
    @GarthMJ

  • Can SCCM be used to set TCP/IP parameters?

    We have an internal DNS appliance ( OpenDNS) and all of our dynamic clients use it as a resolver simply enough using DHCP. However all of our servers have static configs that point to our domain controllers rather than the OpenDNS appliance. This leaves
    us blind as to any potential malware requests coming from our servers since the reports will only include identity information if the appliance is used for the DNS request. So we get a lot of N/A in the identity column of reports that I can neither confirm,
    nor deny, if the source is a server. 
    I need to change the DNS setting of all servers to the OpenDNS appliance. I have a powershell script that goes and replaces any DNS entry found for a domain controller, to the OpenDNS appliance. Now I just need to figure out how to deploy this. It has been
    suggested we use either SCCM or GPO. A computer startup script would be simple enough, the problem is that servers do not reboot ever. And I'm not sure I want to use a logon script for this. So that leaves SCCM as a possibility.   What is the best method
    to deploy and launch a powershell script using SCCM? I can't seem to come up with a solution that I like so far..

    I did create and deploy a package, but it fails and I'm not sure why. I will paste some log output below. I also created a baseline for this that successfully determines compliance, but then the remediation does not happen. I can't figure out why, and am
    so far proving unlucky in determining where to look for clues.
    Here is a failed software deployment for this:
    Successfully prepared command line "C:\Windows\ccmcache\h\openDNSConfiguration.exe" execmgr 11/13/2014 3:09:16 PM
    2076 (0x081C)
    Command line = "C:\Windows\ccmcache\h\openDNSConfiguration.exe", Working Directory = C:\Windows\ccmcache\h\ execmgr 11/13/2014 3:09:16 PM 2076 (0x081C)
    Running "C:\Windows\ccmcache\h\openDNSConfiguration.exe" with 32bitLauncher execmgr 11/13/2014 3:09:16 PM 2076 (0x081C)
    Created Process for the passed command line execmgr 11/13/2014 3:09:16 PM 2076 (0x081C)
    Raising event:
    [SMS_CodePage(437), SMS_LocaleID(1033)]
    instance of SoftDistProgramStartedEvent
    AdvertisementId = "CHR20051";
    ClientID = "GUID:887F5ED7-298B-4CA6-AD2F-E2401532538D";
    CommandLine = "\"C:\\Windows\\ccmcache\\h\\openDNSConfiguration.exe\"";
    DateTime = "20141113200916.881000+000";
    MachineName = "SUPTEST-201201";
    PackageName = "CHR000B5";
    ProcessID = 1932;
    ProgramName = "opendnsscript";
    SiteCode = "CHR";
    ThreadID = 2076;
    UserContext = "NT AUTHORITY\\SYSTEM";
    WorkingDirectory = "C:\\Windows\\ccmcache\\h\\";
    execmgr 11/13/2014 3:09:16 PM 2076 (0x081C)
    Raised Program Started Event for Ad:CHR20051, Package:CHR000B5, Program: opendnsscript execmgr 11/13/2014 3:09:16 PM 2076 (0x081C)
    Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="CHR000B5",ProgramID="opendnsscript", actionType 1l, value NULL, user NULL, session 4294967295l, level 0l, verbosity 30l execmgr 11/13/2014 3:09:16 PM 2076 (0x081C)
    Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="CHR000B5",ProgramID="opendnsscript", actionType 1l, value , user NULL, session 4294967295l, level 0l, verbosity 30l execmgr 11/13/2014 3:09:16 PM 2076 (0x081C)
    MTC task with id {AFBDC445-8174-4716-A132-95F1FEB4CD0B}, changed state from 4 to 5 execmgr 11/13/2014 3:09:16 PM 2076 (0x081C)
    Program exit code -2146232576 execmgr 11/13/2014 3:09:16 PM 3320 (0x0CF8)
    Looking for MIF file to get program status execmgr 11/13/2014 3:09:16 PM 3320 (0x0CF8)
    Script for Package:CHR000B5, Program: opendnsscript failed with exit code 2148734720 execmgr 11/13/2014 3:09:16 PM 3320 (0x0CF8)

  • Powershell updating Maintenance Windows caused a reboot

    I changed my maintenance windows this morning at 10:59 AM. My server was pending a reboot from patching last month and reboot at 11:01 AM. I looked in the RebootCoordinator.log and see this:
    Reboot Coordinator received a SERVICEWINDOWEVENT DELETE Event RebootCoordinator 12/2/2014 11:01:34 AM 48624 (0xBDF0)
    No CCM Identification blob RebootCoordinator 12/2/2014 11:01:34 AM 48624 (0xBDF0)
    Not in Service Mode, check ServiceWindowsManager next RebootCoordinator 12/2/2014 11:01:34 AM 48624 (0xBDF0)
    ServiceWindowsManager has allowed us to Reboot RebootCoordinator 12/2/2014 11:01:34 AM 48624 (0xBDF0)
    User is not logged on RebootCoordinator 12/2/2014 11:01:34 AM 48624 (0xBDF0)
    No CCM Identification blob RebootCoordinator 12/2/2014 11:01:34 AM 48624 (0xBDF0)
    Not in Service Mode, check ServiceWindowsManager next RebootCoordinator 12/2/2014 11:01:34 AM 48624 (0xBDF0)
    ServiceWindowsManager has allowed us to Reboot RebootCoordinator 12/2/2014 11:01:34 AM 48624 (0xBDF0)
    MTC task does not exist. Creating new request. RebootCoordinator 12/2/2014 11:01:34 AM 48624 (0xBDF0)
    MTC allowed us to reboot RebootCoordinator 12/2/2014 11:01:34 AM 48624 (0xBDF0)
    System reboot request succeeded. RebootCoordinator 12/2/2014 11:01:34 AM 48624 (0xBDF0)
    Reboot initiated RebootCoordinator 12/2/2014 11:01:34 AM 48624 (0xBDF0)
    Retry resuming bit-locker TPM PIN protector. Retry count 1 RebootCoordinator 12/2/2014 11:08:12 AM 5440 (0x1540)
    Didn't suspended bit-locker. Do nothing and return. RebootCoordinator 12/2/2014 11:08:12 AM 5440 (0x1540)
    This is the powershell I used:
    ##SCCM.ServerPatchGroup.1.7.0600
    $Schedule = New-CMSchedule -Nonrecurring -Start $ThirdSunday.addhours(+6).tostring("MM/dd/yyyy HH:mm") -End $ThirdSunday.addhours(+7).tostring("MM/dd/yyyy HH:mm")
    $Collection = Get-CMDeviceCollection -Name "SCCM.ServerPatchGroup.1.7.0600"
    Set-CMMaintenanceWindow -CollectionID $Collection.CollectionID -Name "SCCM.ServerPatchGroup.1.7.0600" -Schedule $Schedule
    Is there a log I can look at to see if a user clicked the restart button from the pop on the server or is this supposed to happen? I am assuming its not but I've never seen this before.
    Matt

    Changing the maintenance window(s) like anything else on the server is not immediately effective on the client. The client needs to first know about the change/update before it can act upon it and this only happens when the client updates its machine policy
    which by default happens every 60 minutes.
    Thus, unless the client's machine policy refresh interval happen to be in that very small timeframe between you changing it on the server and the time for it to download, the client did what it was supposed to do.
    Jason | http://blog.configmgrftw.com | @jasonsandys

  • SCCM Windows Updates - Client stuck on Downloading but never finishes

    I am running SCCM 2007 with 200 clients.  I have been sucessfully performing windows updates through SCCM without an issue for about 6 months.  Recently I approved updates released in March and most of the updates installed ok, but there are two, KB938464 and KB958690, which sit on status Downloading for hours until the desktop is switched off at night.  The times reach 14 hours on some machines.
    I have tried to cancel the updates by removing them from the Advertisements and from the Deployment packages but they still try to run everyday on 167 of 200 desktops.  If I manually go to Windows Update and install the updates the issue goes away, however, you can imagine my unwillingness to do this across 167 stations if I can avoid it. 
    How can I do one or both of the following:
    A) Cancel the updates so they no longer want to run on the clients
    B) Fix the issue so the updates download properly.
    The process that I use to approve and deploy updates:
    Under Site Database -> Computer Management -> Software Updates
    I select the updates I want to deploy and add them to a new update list.  I place a check into the box to download the files associated to the updates.
    Once the update list is built I select to deploy the updates, give it a name that represents the update period
    I select a template that deploys but suppresses restart in the updates.
    I select a deployment package, the same one I used for all my past updates
    Download from the Internet
    English
    Schedule
    Finish.
    This has worked sucessfully for months.
    Thank you for any help that can be offered. 

    I think you can use powershell command to modify the cache size
    Here is the link: http://thephuck.com/scripts/use-powershell-to-change-sccm-cache-directory-cache-size/
    $ColQuery = "select * from sms_cm_res_coll_SMS0005E"
    $CollectionMembers = gwmi -computername SCCM_Server -namespace root\sms\site_SMS -Query $ColQuery |sort Name
    foreach($comp in $collectionmembers){
    $server = $comp.name
    write-host -fore green `n`t "working on " $server
    $ccmcfg = gwmi -computer $server -Namespace root\ccm\SoftMgmtAgent -Class CacheConfig
    $ccmcfg.Location = "d:\path\to\cache"
    $ccmcfg.Size = "2048"
    $ccmcfg.Put()
    #stop service, sleep for 10s, start the service
    Get-Service -computer $server ccmexec | Stop-Service
    Start-Sleep 10
    Get-Service -computer $server ccmexec | Start-Service
    write-host -fore green `n`t "finished" $server

  • Loading the SCCM 2012 R2 Cmdlets from within a module

    Hi together,
    In the following article was described how to load the Powershell Module for SCCM 2012:
    http://blogs.technet.com/b/configmgrteam/archive/2013/03/27/powershell-connecting-to-configuration-manager.aspx
    I've taken the code to build a function to load the Powershell Module which works fine when i directly integrate it in my scripts.
    Currently i build a Module called SCCM-HelperFunctions.psm1 and the above mentioned function is one which i want to integrate, i named it "Import-Cmdlets". The Import of my Module works fine,  the function "Import-Cmdlets" is available
    trough IntelliSense and the command ends with no errors in the context of the given Site (ex. "PS CM1:\") but when i try to use SCCM Cmdlets the Command is not found.
    I've checked if the Module was loaded successfully but it isn't. Following is the function included in the Module:
    Function Import-SCCMCmdlets {
    <#
    .SYNOPSIS
    Lädt die SCCM Cmdlets und wechselt in den Kontext der angegebenen Site.
    .DESCRIPTION
    Die Funktion Import-SCCMCmdlets lädt die Powershell Cmdlets und wechselt in den PSDrive Kontext des angegebenen Sitecodes.
    In diesem Kontext können dann die in folgeendem Artikel aufgeführten Cmdlets ausgeführt werden:
    http://technet.microsoft.com/en-us/library/jj821831%28v=sc.20%29.aspx
    .PARAMETER Sitecode
    Eine Zeichenkette mit dem Sitecode der CAS oder Primary Site in dessen Kontext die Cmdlets laufen sollen.
    .EXAMPLE
    Import-SCCMCmdlets -SiteCode "P01"
    .EXAMPLE
    $SiteCode = "P01"
    Import-SCCMCmdlets -SiteCode $SiteCode
    #>
    Param (
    [Parameter(Mandatory=$true)]
    $SiteCode
    $null = Import-Module ($env:SMS_ADMIN_UI_PATH.Substring(0,$env:SMS_ADMIN_UI_PATH.Length – 5) + '\ConfigurationManager.psd1')
    Set-Location "$($SiteCode):" | Out-Null
    if (-not (Get-PSDrive -Name $SiteCode))
    Throw "Beim Versuch das Powershell Modul zu laden und auf das PSDrive $Sitecode zu wechseln trat ein Fehler auf."
    The exact same function works when i copy it to the ISE and run it.
    Does anyone have any ideas and can point me into the right direction? (eventually different workspaces when the function runs from within the module or something like that?)
    Best regards
    Rolf

    Hi together,
    In the following article was described how to load the Powershell Module for SCCM 2012:
    http://blogs.technet.com/b/configmgrteam/archive/2013/03/27/powershell-connecting-to-configuration-manager.aspx
    I've taken the code to build a function to load the Powershell Module which works fine when i directly integrate it in my scripts.
    Currently i build a Module called SCCM-HelperFunctions.psm1 and the above mentioned function is one which i want to integrate, i named it "Import-Cmdlets". The Import of my Module works fine,  the function "Import-Cmdlets" is available
    trough IntelliSense and the command ends with no errors in the context of the given Site (ex. "PS CM1:\") but when i try to use SCCM Cmdlets the Command is not found.
    I've checked if the Module was loaded successfully but it isn't. Following is the function included in the Module:
    Function Import-SCCMCmdlets {
    <#
    .SYNOPSIS
    Lädt die SCCM Cmdlets und wechselt in den Kontext der angegebenen Site.
    .DESCRIPTION
    Die Funktion Import-SCCMCmdlets lädt die Powershell Cmdlets und wechselt in den PSDrive Kontext des angegebenen Sitecodes.
    In diesem Kontext können dann die in folgeendem Artikel aufgeführten Cmdlets ausgeführt werden:
    http://technet.microsoft.com/en-us/library/jj821831%28v=sc.20%29.aspx
    .PARAMETER Sitecode
    Eine Zeichenkette mit dem Sitecode der CAS oder Primary Site in dessen Kontext die Cmdlets laufen sollen.
    .EXAMPLE
    Import-SCCMCmdlets -SiteCode "P01"
    .EXAMPLE
    $SiteCode = "P01"
    Import-SCCMCmdlets -SiteCode $SiteCode
    #>
    Param (
    [Parameter(Mandatory=$true)]
    $SiteCode
    $null = Import-Module ($env:SMS_ADMIN_UI_PATH.Substring(0,$env:SMS_ADMIN_UI_PATH.Length – 5) + '\ConfigurationManager.psd1')
    Set-Location "$($SiteCode):" | Out-Null
    if (-not (Get-PSDrive -Name $SiteCode))
    Throw "Beim Versuch das Powershell Modul zu laden und auf das PSDrive $Sitecode zu wechseln trat ein Fehler auf."
    The exact same function works when i copy it to the ISE and run it.
    Does anyone have any ideas and can point me into the right direction? (eventually different workspaces when the function runs from within the module or something like that?)
    Best regards
    Rolf

  • Trouble with Add-CMDeploymentType and -ScriptInstaller type

    We have a Configuration Manager 2012 SP1 setup and I’m trying to populate the system with all our applications by using PowerShell only. I can create device collections, device collection query rules, applications, application deployment
    types (if msi, appv 4.6 or appv 5), content distributions and deployments. But for some reason I can’t get the Add-CMDeploymentType cmdlet to work with the –ScriptInstaller parameter.
    Example:
    Add-CMDeploymentType -ApplicationName "Testapp" -ScriptInstaller -ManualSpecifyDeploymentType -DeploymentTypeName "Acme Testapp 10.4.5 - SCRIPT" -InstallationProgram "install_testapp.cmd" -DetectDeploymentTypeByCustomScript
    -ScriptType PowerShell -ScriptContent "test-path 'c:\windows'" -AdministratorComment "APP00001" -RunIntallationProgramAs32BitProcessOn64BitClient $false -InstallationBehaviorType InstallForSystem -ContentLocation "\\afs\ltu.se\package\application\APP00001"
    -RunScriptAs32bitProcessOn64bitClient $false -LogonRequirementType OnlyWhenNoUserLoggedOn
    By stripping out everything not necessary I know that it is the –ScriptContent parameter that generates the error “WARNING: Select a correct parameter set.”. I have tried both VBScript and Powershell script types but no matter the value
    of the ScriptContent I get this error. According to the documentation ScriptContent is of type string.
    I find it a bit odd that you can just use scripts for detection methods but I don’t mind if I can get it to work. APPV and MSI works just fine but about 66% of our applications use script based installations.
    As a last resort I could probably do it the same way as on configuration manager 2007 with WMI and Packages but I’d rather move everything over to the application model as we do the migration.

     
    I sat all day with google and tried out code and at the and I was successful in putting together someting that actually worked. The sample script creates both the application and the deployment type at the same time. I would rather use a prebuilt application
    and just add the deployment type but that is work for another day. Hope you find it usefull.
    I did find a good reference here
    http://blogs.technet.com/b/chrad/archive/2012/09/12/configmgr-2012-pcm-walking-through-pcm-plug-in-capabilities.aspx but I could not get the DetectionMethod to work in my code. But I got it working with both VBScript and PowerShell detection scripts and
    I'm fine for now with that.
    -------------ExampleCode---------------
    #Anders Hannus 2013-03-14
    #Some code from:
    http://blog.lechar.nl/2012/04/03/creating-an-sccm-2012-application-with-powershell/
    #Load assemblies
    [Reflection.Assembly]::LoadFile("D:\Microsoft Configuration Manager\AdminConsole\bin\Microsoft.ConfigurationManagement.ApplicationManagement.dll") | out-null
    [Reflection.Assembly]::LoadFile("D:\Microsoft Configuration Manager\AdminConsole\bin\Microsoft.ConfigurationManagement.ApplicationManagement.MsiInstaller.dll") | out-null
    $wminamespace = "Root\SMS\Site_S02"
    $sccmserver = hostname
    #Application info. Normaly read from LDAP database but hardcoded in this example.
    $LTUappMaker = "LTU"        #Maker of application
    $LTUappName = "testapp"        #Name of application
    $LTUappVersion = "1.0"        #Version of application
    $LTUpackageName = "install_ltukerberos_ltu.cmd"  #Command to install application
    $description = "Registry keys so that Windows can find the KRB servers for Realm LTU.SE" #Description of what the program is/does.
    $displayname = "TEST testapp 1.0"     #Diplayname, created from LTUappMaker, LTUappName and LTUappVersion but might be adjusted.
    $app = "APP00001"         #Application id in our database
    $source = "\\server\sccmsource\$app" #Source directory for application.
    $LTUappCheckPath = "C:\Windows\notepad.exe"  #file/folder to detect if application is installed.
    write-host "Creating Application $displayname"
    #Get scopeid
    $identificationClass = [WMICLASS]"\\$($sccmserver)\$($wminamespace):SMS_Identification"
    $cls = Get-WmiObject SMS_Identification -namespace $wminamespace -ComputerName $sccmserver -list
    $tmp = $identificationClass.GetSiteID().SiteID
    $scopeid = "ScopeId_$($tmp.Substring(1,$tmp.Length -2))"
    #Create an unique id for the application and the deployment type
    $newApplicationID = "Application_" + [guid]::NewGuid().ToString()
    $newDeploymentTypeID = "DeploymentType_" + [guid]::NewGuid().ToString()
    #Create SCCM 2012 object id for application and deploymenttype
    $newApplicationID = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.ObjectID($scopeid,$newApplicationID) 
    $newDeploymentTypeID = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.ObjectID($scopeid,$newDeploymentTypeID)
    #Create objects neccessary for the creation of the application
    $newApplication = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.Application($newApplicationID)
    $newDeploymentType = New-Object  Microsoft.ConfigurationManagement.ApplicationManagement.DeploymentType($newDeploymentTypeID,"Script")
    #Setting Display Info
    $newDisplayInfo = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.AppDisplayInfo
    $newDisplayInfo.Title = $displayname
    $newDisplayInfo.Language = "sv-SE"
    $newDisplayInfo.Description = $description
    $newApplication.DisplayInfo.Add($newDisplayInfo)
    #Setting default Language must be set and displayinfo must exist
    $newApplication.DisplayInfo.DefaultLanguage = $newDisplayInfo.Language
    $newApplication.Title = $displayname
    $newApplication.Version = 1.0
    $newApplication.Publisher = $LTUappMaker
    $newApplication.SoftwareVersion = $LTUappVersion
    $newApplication.Description = $app
    #Add all content to the application
    $newApplicationContent = [Microsoft.ConfigurationManagement.ApplicationManagement.ContentImporter]::CreateContentFromFolder($source)
    $newApplicationContent.OnSlowNetwork = "Download"
    #Deployment Type Script installer will be used
    $newDeploymentType.Title = "$displayname - Script Installer"
    $newDeploymentType.Version = 1.0
    $newDeploymentType.Installer.InstallCommandLine = $LTUpackageName
    $newDeploymentType.Installer.UninstallCommandLine = $LTUpackageName.replace("install","uninstall")
    $newDeploymentType.Installer.Contents.Add($newApplicationContent)
    #Detectionmethod
    $testscript = "if (test-path ""$LTUappCheckPath"") {write-host ""The application is installed.""}"
    $newDeploymentType.Installer.DetectionMethod = "Script"
    $newDetectionScript = New-Object Microsoft.ConfigurationManagement.ApplicationManagement.Script
    $newDetectionScript.Language = "PowerShell"
    $newDetectionScript.Text = $testscript
    $newDeploymentType.Installer.DetectionScript = $newDetectionScript
    #Add the DeploymentType to the Application
    $newApplication.DeploymentTypes.Add($newDeploymentType)
    #Serialize the object to an xml file and stuff it into SCCM
    $newApplicationXML = [Microsoft.ConfigurationManagement.ApplicationManagement.Serialization.SccmSerializer]::SerializeToSTring($newApplication,$true)
    $applicationClass = [WMICLASS]"\\$($sccmserver)\$($wminamespace):SMS_Application"
    $newApplication = $applicationClass.createInstance()
    $newApplication.SDMPackageXML = $newApplicationXML
    $tmp = $newApplication.Put()
    #Reload the application to get the data
    $newApplication.Get()
    HI,
    after trying during a long time, I always get the same error when executing line:
    $newDeploymentType = New-Object  Microsoft.ConfigurationManagement.ApplicationManagement.DeploymentType($newDeploymentTypeID,"Script")
    I have change to "MSI" installer and get the same error.
    Any help please.
    New-Object : Exception calling ".ctor" with "2" argument(s): "Invalid deployment technology id: Script"
    At C:\borrar\borrar.ps1:38 char:22
    + $newDeploymentType = New-Object  Microsoft.ConfigurationManagement.ApplicationMa ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
        + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
    SCCM 2012 SP1 CU3 thanks

  • New-CMDeviceVariable not working with -device parameter (PSTypeName mismatch)

    Hi everyone,
    I have a problem with the New-CMDeviceVariable powershell command in SCCM 2012 R2. My script does something like this:
    $ClientID = 'GUID:xxxx-xxxxxxx-xxx-xx'
    $variable = @('Test','ValueTest')
    # Get device properties
    $Device = Get-CMDevice -name $ComputerName | ?{$_.SMSID -eq $ClientID}
    # Add Device variable
    New-CMDeviceVariable -IsMask $false -Device $Device -VariableName $variable[0] -VariableValue $variable[1] -ea 1
    This results in the following error:
    New-CMDeviceVariable : Cannot bind argument to parameter 'Device', because PSTypeNames of the argument do not match the PSTypeName required by the parameter: IResultObject#SMS_R_System.
    So the command expects input of type IResultObject#SMS_R_System while the Get-CMDevice command outputs
    IResultObject#SMS_CombinedDeviceResources. The technet article of the New-CMDeviceVariable clearly states that the correct way to get the device object is through the Get-CMDevice command (see
    article).
    The only way to get this command to work is to use the -DeviceName parameter. Sadly, we have had issues in our test environment where we'd have multiple CMdevices with the same name, hence the SMSID solution. The only other option would be to use the -DeviceID
    parameter. However, I've not been able to get this working using $device.resourceID as a value (which I assume is the ID the command needs). This fails without an error.
    Can anyone explain what the proper way is to get around this issue? I've been racking my brain but I can't seem to find a solution for this.
    Sincerely,
    MicaH

    I'm not sure what the difference is, but with me it runs without problems by using Get-CMDevice. Minor detail, the result is the same as with your other option(s), it doesn't create the variable...
    At this moment a workaround could be to use WMI and do something like this:
    http://www.sepago.de/e/david/2012/05/08/create-machine-variables-in-configuration-manager-2012
    My Blog: http://www.petervanderwoude.nl/
    Follow me on twitter: pvanderwoude

  • Dos command x86 vs x64

    I am trying to out info using the netsh command as follows
    $showready = netsh mbn show ready *
    this works fine if I run it in the x64 powershell. However if I run it in powershell (x86) i get the output "The following command was not found: mbn show ready *." why is it cutting off the netsh?   I am trying to execute the script
    through sccm so I figured it would run the x64 powershell since both sccm and the target os are 64bit. When I look at the logs I see this.
    Running "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NonInteractive -ExecutionPolicy Bypass "C:\WINDOWS\ccmcache\26\Untitled1.ps1" with 32bitLauncher
    why does it run 32bit? and can I force it to run 64bit? better yet why do I get different output between the two? is there a way to get the correct output with the 32bit powershell?
    thanks
    Shaun

    I have a powershell script that runs the netsh mbn show ready * command and the strips out the subscriber ID and simID and drops them into an xml file and the updates the mbn profile. The script works fine when I run it on the machine. It only fails when I
    push it thorugh sccm because it runs with 32bit powershell. The command work with windows 7 just fine.
    The question is how can I force powershell to run the 64bit version? Is there command that can be put into the script?
    Shaun
    You will need to ask that question in the ConfigMgr forums.
    EDIT: Here's a push:
    https://msdn.microsoft.com/en-us/library/windows/desktop/aa384187%28v=vs.85%29.aspx
    Don't retire TechNet! -
    (Don't give up yet - 13,225+ strong and growing)

  • Package behavior in OSD

    Hi,
    If I test a powershell package with SCCM 2012 R2 then will the installation differently during an OSD setup than with just deploying on a computer with a logoff station?
    I am currently doing packaging standard and test and someone ask me if it would be better to test the package on a computer OSD and on logoff station (during a standard deploy).
    Thanks,
    François

    > are they any difference between deploying a package directly to a computer or installing it during
    OSD
    Yes.  Things like ConfigMgr Client Settings and Group Policy are blocked/not yet applied during the task sequence.  On existing clients, Client Settings can handle telling the client to use bypass for a powershell execution policy, so it may work
    there but be blocked by the execution policy in a task sequence.
    You can work around this by having a Run Command Line step sometime before your powershell script with this:
    powershell.exe -Command {Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine -Force}
    You can have another Run Command Line step towards the end that changes it back to Restricted if you don't want to leave it in place.
    I hope that helps,
    Nash
    Nash Pherson, Senior Systems Consultant
    Now Micro -
    My Blog Posts
    If you found a bug or want the product to work differently,
    share your feedback.
    <-- If this post was helpful, please click the up arrow or propose as answer.

  • Administrator account: Permissions issues

    I am working on a PowerShell based utility that I have working fine in Windows 7, but Windows 8 support is giving me some trouble. there are a number of features that work fine with a "regular" Admin account in Windows 7, but require the "Real"
    Admin account in Windows 8. However, that raises an issue and a question.
    1: I have the local Administrator account active on the Windows 8.1 VM. However, I am now unable to connect to the share on my demo "server" (actually a Windows 7 Home VM) The share is configured for Full Control for Everyone. I assume I don't
    need to enable the Administrator account on the server, given the intended behavior of Everyone. But could these local Admin accounts require that? Or is there a different setting that would support access to a share with the local admin account while NOT
    enabling said account on the server?
    2: The intention is for the PowerShell script to be run either by shortcut while logged in as Administrator or via SCCM. The latter is not my area of expertise, so I am wondering, can IT initiate a PowerShell script with elevated privileges via SCCM without
    the need for the local Administrator account? I assume so, as enabling the account on every machine seems like a lot of work and less security, which is not an IT goal. :) 
    Thanks!
    Gordon

    Hi Gordon,
    First, I would like to confirm that if there is any credential created on your share. Is there any error appeared when your access the share?
    Besides the credential issue, we also need to consider the network or firewall factors.
    You can first check the network settings in this article:
    Why can't I connect to other PCs?
    http://windows.microsoft.com/en-HK/windows-8/cant-connect-other-pcs
    Also, you can try to disable firewall on Windows 8 to see what’s going on.
    For your second issue, you can refer to this article:
    PowerShell: Run via SCCM with Administrative rights.
    http://ultimaforsan.squarespace.com/logs/2012/3/7/powershell-run-via-sccm-with-administrative-rights.html
    Hope these could be helpful.
    Kate Li
    TechNet Community Support

Maybe you are looking for

  • Font appears different in Muse (without smooth anti aliasing)

    I am using Google Font Roboto and noticed that it appears thicker when i type it in Muse than in Photoshop. When i have anti-aliasing on 'Strong' in photoshop it mirrors what is showing in Muse, but i prefer the default Smooth anti-aliasing. Is there

  • Issue with Crystal Report & SAP B1 8.8

    Hello, I imported my crystal report in SAP. When I want to edit the report throught SAP, it opens the report on crystal report session. The problem is when I want to save the file. It wants to save in a temporal file. How I can solve it ? where SAP s

  • Query of cs contract

    Hi experts I use resource-related billing for a cs order. and also the cs order   reference a service contract(contract type wv).I want to know if i can set the billing price for the spare part which will be used in the cs order? because Inow i use d

  • PDF Read only Document

    Hi Folks,            How i can make a PDF read only .and it is not a Interactive form.

  • Play SWF in QT

    Is there a way to play SWF (Flash Player) files on QuickTime? Thanks.