Functions/Set-SlackChannel.ps1

<#
.SYNOPSIS
    This function sets properties of a Slack channel.
.DESCRIPTION
    This function sets properties of a Slack channel.
#>

function Set-SlackChannel {
    [CmdletBinding(PositionalBinding=$false)]
    param(
        # The authentication token for Slack
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$token,

        # The name of the channel to set
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$channelName,

        # The channel will be archived or not.
        # If not specified, the state will not be changed.
        [Parameter(Mandatory=$false)]
        [Nullable[boolean]]$archived = $null,

        # The user to add to the channel
        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [String]$addUser,

        # The user to remove from the channel
        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [String]$removeUser,

        # The new purpose of the channel
        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [String]$purpose,

        # The new topic of the channel
        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [String]$topic,

        # The new name of the channel
        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [String]$newChannelName,

        # Select the stream where the messages will be directed.
        [Parameter(Mandatory=$false)]
        [ValidateSet("Information", "Warning", "Error", "None")]
        [String]$outputStream = "Error"
    )

    # Initialize the 'Set Channel' result
    $success = $true

    # Archive or unarchive the channel
    if ($archive) {
        $result = Archive-SlackChannel -Token $token -ChannelName $channelName -OutputStream $outputStream

        # Set the 'Set Channel' result to false if $result is $false
        if (!$result) {
            $success = $false
        }
    }
    elseif ($false -eq $archive) {
        $result = Unarchive-SlackChannel -Token $token -ChannelName $channelName -OutputStream $outputStream

        # Set the 'Set Channel' result to false if $result is $false
        if (!$result) {
            $success = $false
        }
    }

    # Add a user to the channel
    if ($addUser) {
        $result = Add-UserToSlackChannel -Token $token -ChannelName $channelName -UserName $addUser -OutputStream $outputStream

        # Set the 'Set Channel' result to false if $result is $false
        if (!$result) {
            $success = $false
        }
    }

    # Remove a user from the channel
    if ($removeUser) {
        $result = Remove-UserFromSlackChannel -Token $token -ChannelName $channelName -UserName $removeUser -OutputStream $outputStream

        # Set the 'Set Channel' result to false if $result is $false
        if (!$result) {
            $success = $false
        }
    }

    # Set the purpose of the channel
    if ($purpose) {
        $result = Set-SlackChannelPurpose -Token $token -ChannelName $channelName -Purpose $purpose -OutputStream $outputStream

        # Set the 'Set Channel' result to false if $result is $false
        if (!$result) {
            $success = $false
        }
    }

    # Set the topic of the channel
    if ($topic) {
        $result = Set-SlackChannelTopic -Token $token -ChannelName $channelName -Topic $topic -OutputStream $outputStream

        # Set the 'Set Channel' result to false if $result is $false
        if (!$result) {
            $success = $false
        }
    }

    # Rename the channel
    if ($newChannelName) {
        $result = Rename-SlackChannel -Token $token -ChannelName $channelName -NewChannelName $newChannelName -OutputStream $outputStream

        # Set the 'Set Channel' result to false if $result is $false
        if (!$result) {
            $success = $false
        }
    }

    return $success
}