PowerShell/Docs/enter-chat.md

129 lines
2.7 KiB
Markdown
Raw Normal View History

2023-07-29 10:34:04 +02:00
*enter-chat.ps1*
================
2021-11-08 21:36:42 +01:00
2022-02-10 09:01:07 +01:00
This PowerShell script enters a chat using a common network shared file.
2021-11-08 21:36:42 +01:00
2023-07-29 10:04:38 +02:00
Parameters
----------
2021-11-08 21:36:42 +01:00
```powershell
2023-07-29 10:15:44 +02:00
PS> ./enter-chat.ps1 [<CommonParameters>]
2021-11-08 21:36:42 +01:00
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2023-07-29 10:04:38 +02:00
Example
-------
2021-11-08 21:36:42 +01:00
```powershell
2023-08-06 21:36:33 +02:00
PS> ./enter-chat.ps1
2021-11-08 21:36:42 +01:00
```
2023-07-29 10:04:38 +02:00
Notes
-----
2022-11-17 19:46:02 +01:00
Author: Markus Fleschutz | License: CC0
2021-11-08 21:36:42 +01:00
2023-07-29 10:04:38 +02:00
Related Links
-------------
2021-11-08 21:36:42 +01:00
https://github.com/fleschutz/PowerShell
2023-07-29 10:04:38 +02:00
Script Content
--------------
2022-11-17 20:05:34 +01:00
```powershell
2022-11-17 20:02:26 +01:00
<#
.SYNOPSIS
Enters a chat using a common network shared file
.DESCRIPTION
This PowerShell script enters a chat using a common network shared file.
.EXAMPLE
2023-08-06 21:36:33 +02:00
PS> ./enter-chat.ps1
2022-11-17 20:02:26 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
# make sure you adjust this path
# it must point to a network share where you have read and write permissions
$ServerShare = "\\myserver\chathome"
function Enter-Chat
{
param
(
[Parameter(Mandatory)]
[string]
$ChatChannelName,
[string]
$Name = $env:USERNAME,
[Switch]
$ShowOldPosts,
$HomeShare = $ServerShare
)
if ($ShowOldPosts)
{
$Option = ''
}
else
{
$Option = '-Tail 0'
}
$Path = Join-Path -Path $HomeShare -ChildPath "$ChatChannelName.txt"
$exists = Test-Path -Path $Path
if ($exists -eq $false)
{
$null = New-Item -Path $Path -Force -ItemType File
}
$process = Start-Process -FilePath powershell -ArgumentList "-noprofile -windowstyle hidden -command Get-COntent -Path '$Path' $Option -Wait | Out-GridView -Title 'Chat: [$ChatChannelName]'" -PassThru
Write-Host "To exit, enter: quit"
"[$Name entered the chat]" | Add-Content -Path $Path
do
{
Write-Host "[$ChatChannelName]: " -ForegroundColor Green -NoNewline
$inputText = Read-Host
$isStopCommand = 'quit','exit','stop','leave' -contains $inputText
if ($isStopCommand -eq $false)
{
"[$Name] $inputText" | Add-Content -Path $Path
}
} until ($isStopCommand -eq $true)
"[$Name left the chat]" | Add-Content -Path $Path
$process | Stop-Process
}
function Get-ChatChannel
{
param
(
$HomeShare = $ServerShare
)
Get-ChildItem -Path $HomeShare -Filter *.txt -File |
ForEach-Object {
[PSCustomObject]@{
ChannelName = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
LastActive = $_.LastWriteTime
Started = $_.CreationTime
}
}
}
2022-11-17 20:05:34 +01:00
```
2022-11-17 20:02:26 +01:00
2023-09-01 17:53:03 +02:00
*(generated by convert-ps2md.ps1 using the comment-based help of enter-chat.ps1 as of 09/01/2023 17:51:50)*