troubleshooting Question

Use PowerShell parameter with .ps1 file name

Avatar of Jason Crawford
Jason CrawfordFlag for United States of America asked on
PowershellAzure
5 Comments1 Solution91 ViewsLast Modified:
Below is a simple script to force either a full or delta sync with Azure AD Connect.  What I want to be able to do is call the .ps1 file from a PowerShell command prompt and immediately follow the file name with the -Type parameter so it would look something like this:

> .\Force-ADSync.ps1 -Type Delta

or

> .\Force-ADSync.ps1 -Type Full

Here is the script I'm working with:

function Force-ADSync {
    [CmdletBinding()]
    Param (
        [Parameter(position=0,mandatory=$true)][String]$type
    )

    switch ($type) {
        Delta {
            Invoke-Command -ComputerName server.domain.local -ScriptBlock {
                Import-Module adsync
                Start-ADSyncSyncCycle -PolicyType Delta
            }
        }
        Full {
            Invoke-Command -ComputerName server.domain.local -ScriptBlock {
                Import-Module adsync
                Start-ADSyncSyncCycle -PolicyType Initial
            }
        }
    }
}
Thanks in advance!
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros