0

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

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

1 Comment

More PoSh: $servername = ($scriptPath -replace '^\\\\' -split '\\')[0].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.