Pass a blank variable

Hi Team.

Hoping someone might be able to help get around a small issue.

I have a Workflow that has a Parameter of Location. Values assigned to that are for example Server1 , Server2 , Server3 , Server4

Now when you run the Work flow and select Server2 , 3 , or 4 it adds this value to the $Location variable and connects accordingly. The Issue is that when people select Server1 i actually dont want anything passed in to the variable and for it to be blank. As an example if i was to hard code these it would be something like

https://DomainName-admin.sharepoint.com

https://DomainNameServer2-admin.sharepoint.com

https://DomainNameServer3-admin.sharepoint.com

https://DomainNameServer4-admin.sharepoint.com

Any suggestions on how to work around this?

Code below

$Location = $Workflow.Parameter("Location")

#Connection Propertis
$SPURL = "https://DomainName$Location-admin.sharepoint.com"
$ClientID = "something something"
$TenantName = "DomainName.onmicrosoft.com"
$Thumbprint = "something something"

#CSV Export Location
$CSVExport = "C:\$Location-Export.csv"

#Connect to SharePoint Online
Connect-PnPOnline -Url $SPURL -ClientId $ClientID -Tenant $TenantName -Thumbprint $Thumbprint

Hi,

Firstly, when posting code in the forum, please can you use the preformatted text </> button. It really helps us with readability, and copying and pasting your code (we don’t have to faff about replacing curly quote marks to get things working).

How to format code on PowerShell.org

Would something like this work?

$Location = $null

if ($Workflow.Parameter("Location") -ne 'Server1') {
    $Location = $Workflow.Parameter("Location")
}

I’ve used the syntax from your post but is Parameter actually a method? I would have assumed Parameter was a hashtable, and you’d use square brackets.

Hello.

Apologies i was running out the door and forgot to format the code. i will check the code out tomorrow. However although i want the https:// URL to ignore Server1 i actually use it on the line with the CSV file. I guess the file name would be -Export.CSV rather than server1-export.csv

$CSVExport = “C:$Location-Export.csv”

OK, use a switch statement to set the URL. I would also splat the parameters:

$Location = $Workflow.Parameter("Location")

switch ($Location) {
    'server1' { $SPURL = 'https://DomainName-admin.sharepoint.com' }
    default   { $SPURL = "https://DomainName$Location-admin.sharepoint.com"}
}

#Connection Properties
$CxParams = @{
    URL        = $SPURL
    ClientID   = "something something"
    Tenant     = "DomainName.onmicrosoft.com"
    Thumbprint = "something something"
}

#CSV Export Location
$CSVExport = "C:\$Location-Export.csv"

#Connect to SharePoint Online
Connect-PnPOnline @CxParams

Thank you mate. This is perfect and runs as it should.

As always i learn something along the way. Really appreciate your help.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.