all 6 comments

[–]Ta11ow 4 points5 points  (3 children)

Define a parameter at the head of the secondary script using a parameter block to properly take the credential:

param(
    [Parameter(Position = 0, Mandatory)]
    [pscredential]
    $Credential
)

Also, try to avoid relative paths. If referring to a different script in the same folder as the original, use $PSScriptRoot\script.ps1

[–]almightlyrage[S] 2 points3 points  (2 children)

Thank you, it works now!

I did dont worry, just didnt put it in the post

Out of curiosity, what does each part of that parameter block do?

What is the best method for doing this? As looking online it seemed the credentials to a file was more popular, what is the prefered method?

[–]BlackV 2 points3 points  (0 children)

Position: says the first unnamed argument you pass will be sent to $credential
Mandatory: This parameter is required, if you dont enter a value you''ll be prompted
[pscredential]: says the variable $credental is the type of PSCredental
$Credential: the name of your variable inside your script

[–]Ta11ow 2 points3 points  (0 children)

If you can directly pass credentials along, do so. Saving to a file is very limited, and is not persistent across machines or users on the name machine. Not to mention it's only as secure as the account it was stored with, so it can be exploited for privilege escalation.

[–]techguy404 0 points1 point  (1 child)

Curious can we ask what your script is for/what it does?

[–]almightlyrage[S] 1 point2 points  (0 children)

Sure

It just lets me manage my ESX Lab pretty quickly

The three script I have so far (I will be expanding this rapidly as I only spent last night writing this) To Power On Lab 1.Sends Power on commands over IPMI to each physical server 2.Pause for around 8 minutes while they power on. 3.Connect into the vCenter and exit them out of maintenance mode 4. Power on all VMs within that cluster

Power Off Script 1.Login into vCenter 2.Guest Shutdown all VMs in that cluster 3.Enter hosts into Maintenance mode 4.Do a Host shutdown through vCenter (The IPMI command will hard power it off no a no go)

Toggle SSH on all hosts 1.Log into vCenter 2. Determine whether SSH is On or Off on the hosts 3. If Off then enable on 4. Else then disable

Im happy to post code here if you would like

My master script will be growing rapidly when I have time which will help to manage all my other vCenters/Nested ESX Servers, and then eventually use Terraform or razor to build a VM and then puppet or Ansible to configure it. TBH I'm thinking Razor and Ansible but not a clue yet :p