Hi All,
I have one dedicated server called PRODAZAD-V which is running Azure Active Directory Synch to Office 365.
Enter-PSSession -ComputerName PRODAZAD-V
Install-Module ADSync
Import-Module ADSync
Start-ADSyncSyncCycle -PolicyType Delta
How can I execute the PowerShell code above to force it to Synch from my PowerShell ISE on my laptop without installing the module & loading it every time?
Thank you in advance.
I believe above code is not from a script and you have a Tab opened in ISE and the above code snippet in that session.
You don’t need to Install the module every time, if the target node is PowerShell v3 (hope you are not using the deprecated v2) then even the Import module part is also not required as there is a module autoload feature in PowerShell from v3 onwards.
if you haven’t heard about implicit remoting, please check it here, it will usefull for you.
[quote quote=122709]I believe above code is not from a script and you have a Tab opened in ISE and the above code snippet in that session.
You don’t need to Install the module every time, if the target node is PowerShell v3 (hope you are not using the deprecated v2) then even the Import module part is also not required as there is a module autoload feature in PowerShell from v3 onwards.
if you haven’t heard about implicit remoting, please check it here, it will usefull for you.[/quote]
KV,
My goal is to be able to double click the file as.Batch file or as.PS1 so I can update the Azure AD Synch quickly.
Hi,
you would need to utilize PowerShell remoting for this task. The below code snippet is what i had created for another script.
Function Get-UPNAzureADSyncStatus {
param(
[object]$SyncJobStatus
)
$Script:ADSyncStauts = $null
if($SyncJobStatus -eq "Success"){
$SyncInProgress = $true
do{
$SyncInProgress = Invoke-Command -ComputerName $AzureADSyncServerFQDN -ScriptBlock {Get-ADSyncScheduler | select-object -ExpandProperty SyncCycleInProgress} -ErrorAction Stop
if($SyncInProgress -eq $true){
Start-Sleep -Seconds 10
}#end_SubIF
}While($SyncInProgress -eq $true)
$Script:ADSyncStauts = "Complete"
return
}#END_IF
}#END_ScriptFunction
Function Start-UpnUpdateAzureADSync{
param(
[String]$ServerName
)
filter Out-Default { $_ | Out-Null }
$JobStatus = "Success"
$AzureADjobRunStatus = "Running"
while($AzureADjobRunStatus -eq "Running"){
Get-UPNAzureADSyncStatus -SyncJobStatus $JobStatus
if($($Script:ADSyncStauts) -eq "Complete"){
$ADSyncStart = Invoke-Command -ComputerName $ServerName -ScriptBlock {Start-ADSyncSyncCycle -PolicyType Delta} -ErrorAction Stop
Return $ADSyncStart.Result
}#END_IF
}#While
}#END_ScriptFunction
Regards
I have the following code in my powershell profile that handles this task
[pre]
function Start-DeltaSync
{
$session = New-PSSession -ComputerName PRODAZAD-V
Invoke-Command -Session $session -ScriptBlock {Start-ADSyncSyncCycle Delta}
Remove-PSSession $session
}
[/pre]
@postanote, Cool, thanks man
@Spietersz, how to execute that function in Visual Studio code?
@Jon, thanks, man.