syparon Posted May 21, 2014 Report post Posted May 21, 2014 Hi all, My goal is to Install applications with Dynamic Varibales which are set in a Device Collection. I created a query to link my device collection with an AD Security group (<-- It works) So during the task sequence I put the Computer as member of a security group (<-- It works) After this I execute a script which make a forest discovery and an update membership for the device Collection (Script is below) Param( [string[]]$Collections ) #/ Session Creation /*--------------------------------------------------------------------------------------------- Try { $MySession = New-PSSession [serverHostName] } Catch{ Write-Host "Error: $($_.Exception.Message)" } #/----------------------------------------------------------------------------------------------------------------- Invoke-Command -session $MySession -ArgumentList $Collections -script { param ($Collections) $Collections = $Collections.Split(',') #/ Import Module + Change Drive /*--------------------------------------------------------------------------------- Import-Module "E:\Services\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1" $SCCMDrv = Get-PSDrive -PSProvider CMSite cd "$($SCCMDrv):" #/----------------------------------------------------------------------------------------------------------------- ###################################################################################### ################################ Forest Discovery #################################### ###################################################################################### Invoke-CMForestDiscovery -SiteCode "[siteCode]" ## ###################################################################################### #/---------------------------------------------------------------------------------------------------------------/# ###################################################################################### ################### Update Membership - Software Baseline ######################## ###################################################################################### $SiteCode = "[siteCode]" $SiteServer = "[serverHostName]" foreach ($Value in $Collections) { echo $Values Try{ $CollectionQuery = Get-WmiObject -Namespace "Root\SMS\Site_$SiteCode" -Class SMS_Collection ` -ComputerName $SiteServer -ErrorAction STOP -Filter "Name='$Value'" $CollectionQuery.RequestRefresh() } Catch{ Write-Host "Error: $($_.Exception.Message)" } } ## ###################################################################################### EXIT } Start-Sleep -s 30 (The task picture is joined to this topic) When I execute the script on a machine it works well and when I execute it through a task sequence I can see in SMSTS log that the task is successfull (Successfully completed the action (Refresh membership) with the exit code 0) But it does not update the membership at all ! Is it because of the configuration manager client ? or something else maybe ? I hope I was clear Thanks in advance Quote Share this post Link to post Share on other sites More sharing options...
Peter van der Woude Posted May 21, 2014 Report post Posted May 21, 2014 The thing with PowerShell in task sequences is usually that it shows the result of 0, because it succesfuly started the script. That doesn't mean that it didn't fail. It could be that there are a some errors a few lines abow it. 1 Quote Share this post Link to post Share on other sites More sharing options...
syparon Posted May 22, 2014 Report post Posted May 22, 2014 ok Thanks, I have tried to output the result in a file but it seems that it is not possible. Is there another way to capture log about my script or redirect the output in a file because I want to know the result of my script Quote Share this post Link to post Share on other sites More sharing options...
syparon Posted July 7, 2016 Report post Posted July 7, 2016 I've found a solution, actually the device collection variables have to be set on the collection where the TS is deployed. Otherewise it will not work and even if you add the freshly deployed machine in the collection during the OSD. Quote Share this post Link to post Share on other sites More sharing options...