## Create a session$s=New-PSSession<computer-name>## Run command(s) on the removeInvoke-Command-Session$s{<command(s)torun>}## Close the remote sessionRemove-PSSession$s
# Create a session$Session=New-PSSession-ComputerName"Server01"-Credential"Contoso\User01"# Copy item from remote $session to local -Destination)Copy-Item"C:\MyRemoteData\test.log"-Destination"D:\MyLocalData\"-FromSession$Session
On Linux, where everything is better and easier, you just run uptime to get a machine's uptime. On Windows, you have to do extra stuff because... Powershell...
On laptops or devices with portable power, you can generate a battery report with the following command (find the report at the path you put after /output):
Write-Host"This is the first part of a long string, with no formatting."-NoNewline;Write-Host"This part of the string will appear inline (on the same line) as the previous string,"-NoNewline;Write-Host"and can even be broken up mid-sentence! Check the source code to see this in action."-NoNewline;Write-Host""-NoNewline;Write-Host"And I'm purple, just because"-ForegroundColorpurple-NoNewline;Write-Host"Ok that's all."
Set/Unset environment variables
Warning
You must be in an elevated/administrative prompt for these commands.
functionSet-EnvVar{<# Set an environment variable. If -Target Machine or -Target User, the env variable will persist between sessions. Usage: Set-EnvVar -Name <name> -Value <value> Set-EnvVar -Name <name> -Value <value> -Target Machine Params: Name: The name of the environment variable Value: The value of the environment variable Target: The scope of the environment variable. Machine, User, or Process Example: Set-EnvVar -Name "EXAMPLE_VAR" -Value "example value" Write-Host $env:EXAMPLE_VAR #>param([string]$Name,[string]$Value,[ValidateSet('Machine','User','Process')][string]$Target='User')Write-Host"Setting [$Target] environment variable "$Name"."If($Target-eq'Process'){Write-Warning"Environment variable [$Target] will not persist between sessions."}else{Write-Information"Environment variable [$Target] will persist between sessions."}try{[System.Environment]::SetEnvironmentVariable($Name,$Value,[System.EnvironmentVariableTarget]::$Target)}catch{Write-Error"Unhandled exception setting environment variable. Details: $($_.Exception.Message)"}}
functionRemove-EnvVar{<# Remove/unset an environment variable. Usage: Remove-EnvVar -Name <name> Remove-EnvVar -Name <name> -Target Machine Params: Name: The name of the environment variable Target: The scope of the environment variable. Machine, User, or Process Example: Remove-EnvVar -Name "EXAMPLE_VAR" Write-Host $env:EXAMPLE_VAR #>param([string]$Name,[ValidateSet('Machine','User','Process')][string]$Target='User')try{[System.Environment]::SetEnvironmentVariable($Name,$null,[System.EnvironmentVariableTarget]::$Target)}catch{Write-Error"Unhandled exception removing environment variable. Details: $($_.Exception.Message)"}}