Powershell Variables - Workflow Automation

Hi. 

I am looking to move some scripts over to ARS to run as a scheduled task. If we run this manually we are asked to select a location value which then maps to the correct CSV file in a specified location. 

Whats the best way of passing a value to the script at run time? I assume it would be four scheduled tasks based on how many locations we need to use? 

Thanks in advance 

function Run-Active-Roles ($Request)
{

Import-OneDrive_URL

}

function Import-OneDrive_URL {   
    param (   
        $AzureLocation = (Read-Host -Prompt 'Enter Azure location. GBR or CHE or APC or NAM')   
)

#Import CSV
$CSVImport = "C:\ARS-Scripts\_OneDrive_Export\$AzureLocation-OneDrive-for-Business-Users.csv"

Connect-QADService -Service "ARS.FQDN_HERE" -Proxy
Import-Csv $CSVImport | ForEach-Object {

$CurrentUser = [string]$_.UserName
$OneDriveSiteUrlContents = [string]$_.OneDriveSiteUrl

$TargetUser = Get-QADUser -LdapFilter "(userprincipalname=$CurrentUser)" | select -expandproperty DN

Set-QADUser -Identity $TargetUser -ObjectAttributes @{"ARS_VA_NAME_HERE"=$OneDriveSiteUrlContents}
    }
}

Parents Reply Children
  • Thanks thats what was confusing me. The powershell code was to set the parameter but if i can just do it via the GUI and its the same thing then thats great. 

    Then just call it like $MyParameter = $Task.DirObj.Parameters.Value("Test_Parameter").Value

    I will check this out when i logon tomorrow. 

  • Hi. 

    So i have created a new scheduled task. Assigned it the AzureLocation as the parameter value on the task and given it a value. It runs correctly when executed. This is epic stuff. Would be amazing to only have a single script and single scheduled task that can take the different values for the AzureLocation but right now i will be happy to have a single script and four scheduled tasks each with a different value for AzureLocation.  

    So now i am set with either Automation work flows that can be run from the WI or scheduled tasks. 

    $AzureLocation = $Task.DirObj.Parameters.Value("AzureLocation").Value
    
    switch ($AzureLocation) {
        'SERVER1' { $SPURL = 'https://domainname-admin.sharepoint.com' }
        default   { $SPURL = "https://domainname$AzureLocation-admin.sharepoint.com"}
    }
    
    #Connection Properties
        $CxParams = @{
        URL = $SPURL
        ClientID = "something"
        Tenant = "something.onmicrosoft.com"
        Thumbprint = "something"
    }
    
    #CSV Export Location
    $CSVExport = "C:\$AzureLocation-OneDrive.csv"
    
    #Connect to SharePoint Online
    Connect-PnPOnline @CxParams
    
    function Export-OneDrive-URL {  
    
    $Result=@()
    #Get all office 365 personal sites
    $oneDriveSites = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"
    $oneDriveSites | ForEach-Object {
    $site = $_
    $Result += New-Object PSObject -property @{ 
    UserName = $site.Owner
    OneDriveSiteUrl = $site.URL
    }
    }
    
    $Result | Select UserName, OneDriveSiteUrl | where {![string]::IsNullOrWhiteSpace( $_.UserName)} | Sort-Object UserName |
    Export-Csv $CSVExport -NoTypeInformation -Encoding UTF8 -Force
    
    }
    
    Export-OneDrive-URL

  • You could also consider creating multiple Parameters (AzureLocation1, AzureLocation2...) within a single Scheduled Task, each Parameter containing a value you'd like the script to consider, and then build a bit of extra logic at the beginning of the script to pick one.