user2857897
user2857897

Reputation: 31

powershell get computer name where is script located when running from another computer

I have script that is executable from another computer.

How to get comptername of location script? Just name, not full path (because the script can be distributed anywhere) Thanks

Upvotes: 0

Views: 315

Answers (1)

user2857897
user2857897

Reputation: 31

Solved on my own. :-) Hope that helps someone.

$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
[string[]]$sth = $scriptPath.Split('\',[System.StringSplitOptions]::RemoveEmptyEntries)
$servername = $sth[0]

Upvotes: 1

Related Questions