# Administering Remote Computers

Find Command and Help Command

```powershell
#Find command 

Get-Command -Module ChangeMe

#help Command

Help changeMe
```

Prior to any engagements ensure Remote Signed Policy is on

```powershell
Set-ExecutionPolicy RemoteSigned
```

Enable Remote Incomming Connections

```powershell
Enable-PSremoting
```

List the commands that contain session configuration

```powershell
help *sessionconfiguration*

<# use code below to view the session configs of the PC#>

Get-PSSessionConfiguration
```

To establish a one-to-one connection to a PC&#x20;

{% code overflow="wrap" %}

```powershell
Enter-PSSession -ComputerName "PC_NAME"

#Make the connection persistent
$sessionOption = New-PSSessionOption -IdleTimeout 86400  # Set an idle timeout of 24 hours (86400 seconds)
$PcConn  = New-PSSession –ComputerName 'PC_Here' -SessionOption $sessionOption

#To verify connectivity type the variable name and it will provide the connection session

$PcConn 

```

{% endcode %}

To exit a session

```powershell
Exit-PSSession
```

To run a command on remote computers by means of remoting and executing the command Get-NetAdapter : Note (Change the -ScriptBlock \[theCommand you want executed])

{% code overflow="wrap" %}

```powershell
Invoke-Command -ComputerName $pcConn -ScriptBlock {Get-NetAdapter -Physical}
```

{% endcode %}

View memebers of Get Process

```powershell
Get-Process | Get-Member
```

Display list of modules for LON-DC1 & Search for available module&#x20;

{% code overflow="wrap" %}

```powershell
Get-Module *StringHere* -ListAvailable

#Get Module with Session and a search pipe
    
Get-Module -ListAvailable -PSSession $(SessionName Variable from Persisten Connection)|Get-Module –ListAvailable –PSSession $dc |
Where { $_.Name –Like '*//ChangeMe*' } 
```

{% endcode %}

Import Module & Check for Shares

```powershell
Import-Module -PSSession $pcConn -Name SMBShare -Prefix DC

GET-DCSMBShare
```

Create a report with Windows Firewall Rules

<pre class="language-powershell" data-overflow="wrap"><code class="lang-powershell">3Find the command that displays firewall rules

Get-Command -Module NetSecurity

#To Display a list of enabled firewall rules on Computers

<strong>Invoke-Command -Session $pcConn -ScriptBlock {Get-NetFirewallRule -Enabled True | Select Name, PSComputerName}
</strong></code></pre>

List Local Hard Drives

```
Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3"
```

Producce HTML Report for Previous Command

{% code overflow="wrap" %}

```powershell
Invoke-Command -Session $pcConn -ScriptBlock {Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-HTML -Property PSComputerName,DeviceID,FreeSpace,Size}
```

{% endcode %}

Remove Session

```powershell
Get-PSSession | Remove-PSSession
```
