Curious if anyone has found that by setting the -ForeceRefresh, that the cmdlet never finishes, I let this run overnight and never finished, It only has around 27k files.
I run it nightly on all our data sources. It takes many hours (especially since I kick off 20 of them over the course of an hour) but it does complete.
I just checked my script's logs, I start my process at midnight and launch 5 datasources at a time every 30 minutes. Takes until 4am until the last one completes.
You're probably going to have to check with your db group to see what's hanging this up. the logging on it on the projectwise side isn't very granular.
i have our datasources in a sql table. I have a column in the sql table that identifies which group that datasource is in.
I then loop through all group 1 datasources and use Start-Job to launch a script in parallel to handle that datasource's refresh. when the loop is done it waits 1800 seconds then starts the next group of datasources in parallel. and so on until it's out of groups.
Hi Kevin,
I believe what you have done is exactly what I am trying to do. I am reading a bunch of datasources that are listed in a SQL table and loging in to run the GET-PWStatistics, and as you know this takes ages and doesn't seem to finish, running sequentially like this just doesn't work.
#Read thru the contents of the job definitions foreach($Job in $Jobs){ #Open Connection if (New-PWLogin -DatasourceName $Datasource -UserName $username -Password $SecurePassword -ErrorAction Stop){ Get-PWStatistics -ForceRefresh -IgnoreLastLoginCount } }
I see that you are using the "Start-Job" to launch your processing in parallel, and I have tried a few things to do the same, I am just a little stuck as it doesn't seem to be working for me. I was trying something like this, I haven't used "Start-Job" function before
function RunPWStatistics{ #Open Connection if (New-PWLogin -DatasourceName $Datasource -UserName $username -Password $SecurePassword -ErrorAction Stop){ Get-PWStatistics -ForceRefresh -IgnoreLastLoginCount } } #Read thru the contents of the job definitions foreach($Job in $Jobs){ Start-Job -ScriptBlock {RunPWStatistics} | Wait-job -Timeout 600 }
When you use Start-Job it starts a completely new process. This means it doesn't have access to any variables declared outside of the scriptblock you pass in (maybe access to global variables, but i wouldn't use globals)
Change your function to accept parameters:
function RunPWStatistics{ CmdletBinding()] Param ( [Parameter( Mandatory = $True, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, HelpMessage = 'datasource name' )] [String]$Datasource, [Parameter( Mandatory = $False, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, HelpMessage = 'Datasource Username' )] [String]$UserName, [Parameter( Mandatory = $False, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, HelpMessage = 'Datasource Username' )] [SecureString]$SecurePassword ) #Open Connection if (New-PWLogin -DatasourceName $Datasource -UserName $username -Password $SecurePassword -ErrorAction Stop){ Get-PWStatistics -ForceRefresh -IgnoreLastLoginCount } }
Then change your start-job loop to include the parameters
#Read thru the contents of the job definitions foreach($Job in $Jobs){ Start-Job -ScriptBlock {RunPWStatistics} -ArgumentList @($datasource,$username,$securepassword) | Wait-job -Timeout 600 }
According to my notes the arguments in the ArgumentList array should be in the order they are defined in the function.