Hi,
I’m trying to use the cmdlet Start-Process using the ArgumentList to make a variable of the current session available on the new process.
I have tried using like this:
$ADCred = Get-Credential $Path = ".\ManageRemoteComputers.ps1" Start-Process PowerShell -Credential $ADcred -ArgumentList "-File $Path", $ADCred
And inside the ManageRemoteComputers.ps1 file, using this:
$CurrName = Read-Host "Type the name of the computer that you want to rename"
$NewName = Read-Host "Type the new name of the computer"
Invoke-Command -ComputerName $CurrentName -Credential $ADCred -ArgumentList $ADCred -ScriptBlock {
param ($ADCred)
Rename-Computer -ComputerName $CurrentName -NewName $NewName -Force -DomainCredential $ADCred -verbose
}
But then a new credential window pop-up…
Any ideas?