Skip to content

Instantly share code, notes, and snippets.

@Jineeshak
Created November 3, 2023 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jineeshak/ea082c5259dd8f6f78b14dc879822a01 to your computer and use it in GitHub Desktop.
Save Jineeshak/ea082c5259dd8f6f78b14dc879822a01 to your computer and use it in GitHub Desktop.
function Get-PowerView {
[CmdletBinding()]
[OutputType([string[]])]
Param (
[Parameter(Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string]$ComputerName = "localhost",
[Parameter(Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=1)]
[string]$ScriptBlock = "Get-NetUser"
)
Begin {
$ErrorActionPreference = "Stop"
$PSSession = New-PSSession -ComputerName $ComputerName -Credential $Credential
Invoke-Command -ScriptBlock $ScriptBlock -Session $PSSession
}
Process {
$Results = Receive-PSSession $PSSession
Write-Output $Results
}
End {
Remove-PSSession $PSSession
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment