Skip to content

Instantly share code, notes, and snippets.

@indented-automation
Last active July 30, 2018 18:16
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 indented-automation/3dd8d9eb3ae37cf7b198b5a6dbcab777 to your computer and use it in GitHub Desktop.
Save indented-automation/3dd8d9eb3ae37cf7b198b5a6dbcab777 to your computer and use it in GitHub Desktop.
# 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