Question: Here is the data frame.

```
Number UrinateFrequently  UrgeUrinate
1      occasionally       rarely
2      rarely             rarely
3      occasionally       occasionally
4      rarely             always
5      frequently         always

```

I can only summarise one column at a time like this

```
a %>% group_by(UrinateFrequently) %>% summarise(n = n())

 UrinateFrequently     n
  <fct>             <int>
1 rarely                2
2 occasionally          2
3 frequently            1

```

How can I summary all all of them at a time like this?

```
               UrinateFrequently  UrgeUrinate
rarely               x                 x
occasionally         x                 x
frequently           x                 x
always               x                 x

```

I have tried this but it doesn't work.

```
a %>% summarise(across(everything(),list(group_by(.),n = n(.))))

```

Answer: 
So, as I said in my comment, you have 2 options to copy the script from a remote host to another remote host.

It is possible that the first option may give you a **double-hop** error, if that was the case you should be looking at [**`CredSSP`**](https://devblogs.microsoft.com/scripting/enable-powershell-second-hop-functionality-with-credssp/) or **Service Principal Name / Kerberos Delegation**.

### Option 1: With `Invoke-Command`

```
$serverlist = Get-Content "C:\serverlist.txt"

$scriptBlock = {
    # Since this is already happening on the scope of $server (remote host)
    # you don't really need to use a network path.
    # If you still want to use it, you can do, \\localhost\D$\scripts too.
    if(-not(Test-Path "D:\scripts"))
    {
        Write-Host "Creating new folder...... "
        New-Item -Path "D:\scripts" -ItemType Directory
    }

    sleep -Seconds 4
    Write-Host "Copying the script to destination...."
    # Not sure if "scirpts" is intended or a typo here
    Copy-Item -Path "\\hostx\copyshare\scirpts\IISLog.ps1" -Destination "D:\scripts\" -Verbose
}

foreach ($server in $serverlist)
{
    Invoke-Command -ComputerName $server -ScriptBlock $scriptBlock   
}

```

### Option 2: Without `Invoke-Command`

```
$serverlist = Get-Content "C:\serverlist.txt"

foreach ($server in $serverlist)
{
    if(-not(Test-Path "\\$server\D$\scripts"))
    {
        Write-Host "Creating new folder...... "
        New-Item -Path "\\$server\D$\scripts" -ItemType Directory
    }

    sleep -Seconds 4
    Write-Host "Copying the script to destination...."
    Copy-Item -Path "\\hostx\copyshare\scirpts\IISLog.ps1" -Destination "\\$server\D$\scripts\" -Verbose
}

```

Now, to understand the `$using:`, or ***how to use local variables on remote hosts***, here is a link for [Example 9 of MS Docs](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-7.1#example-9--include-local-variables-in-a-command-run-on-a-remote-computer) which explains it really well.

You can also use `-ArgumentList` to pass the variables to the remote host, and then use the `$args` automatic variable or a `param(...)` block.
Try replacing this line \$server\D$\scripts with the following so that it expands correctly (your error code shows three backslashes)

```
"\\$server\D$\scripts"

```

I feel that this script could use a re-write all together - if you're invoking a command on a remote computer, you can reference that computers folder structure directly without using remote shares.

For example, use `"D:\scripts"` instead of `\\server1\D$\scripts`