Last active
July 30, 2018 18:16
-
-
Save indented-automation/3dd8d9eb3ae37cf7b198b5a6dbcab777 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Parameters used to authenticate remote connections | |
$remoteParams = @{ | |
Credential = Get-Credential | |
ComputerName = $env:COMPUTERNAME | |
} | |
# Parameters which are specific to Test-WSMan | |
$testWSMan = @{ | |
Authentication = 'Default' | |
ErrorAction = 'SilentlyContinue' | |
} | |
# By default, do not pass any extra parameters to New-CimSession | |
$newCimSession = @{} | |
if (-not (Test-WSMan @testWSMan @remoteParams)) { | |
# If WSMan fails, use DCOM (RPC over TCP) to connect | |
$newCimSession.Add('SessionOption', (New-CimSessionOption -Protocol Dcom)) | |
} | |
# Parameters to pass to Get-CimInstance | |
$getCimInstance = @{ | |
ClassName = 'Win32_Service' | |
CimSession = New-CimSession @newCimSession @remoteParams | |
} | |
Get-CimInstance @getCimInstance | |
# Array splatting | |
Rename-Item oldname.txt newname.txt | |
# Becomes | |
$renameItem = 'oldname.txt', 'newname.txt' | |
Rename-Item @renameItem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment