VMware Cloud Community
jravnsba1
Contributor
Contributor
Jump to solution

Create alias in $profile to connect to all vCenters

Is is possible to create an alias in $profile to connect to all your vCenters ?

I have tried but it doesn't work as expected:

$credential = import-clixml -path 'C:\documents\PowerCLI\My-credfile.xml'

$vCenterServers = @("vcsa1","vcsa2","vcsa3","vcsa4","vcsa5")

new-alias allvc connect-viserver $vCenterServers -Credential $credential

If I run it from commandline it works:

$credential = import-clixml -path 'C:\documents\PowerCLI\My-credfile.xml'

$vCenterServers = @("vcsa1","vcsa2","vcsa3","vcsa4","vcsa5")

connect-viserver $vCenterServers -Credential $credential

Joern Ravnsbaek
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can create an alias for a cmdlet, but not for a cmdlet with parameters.

Why don't you define a function in your profile instead?

function allvc {

    $credential = import-clixml -path 'C:\documents\PowerCLI\My-credfile.xml'

    $vCenterServers = @("vcsa1","vcsa2","vcsa3","vcsa4","vcsa5")


    connect-viserver $vCenterServers -Credential $credential

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

You can create an alias for a cmdlet, but not for a cmdlet with parameters.

Why don't you define a function in your profile instead?

function allvc {

    $credential = import-clixml -path 'C:\documents\PowerCLI\My-credfile.xml'

    $vCenterServers = @("vcsa1","vcsa2","vcsa3","vcsa4","vcsa5")


    connect-viserver $vCenterServers -Credential $credential

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos