What i got is two scripts.
Connector.ps1 which is run locally (planning to exe-wrap this)
mainscript.ps1 which is located on a DC.
Connector is essentially the part of the script that authenticates to the remote server and launches the mainscript.
do{
$ADadmin=read-host"Input administrative account to use"
$cred=Get-Credential$adadmin
$ADuser=$cred.username
$ADpass=$cred.GetNetworkCredential().password
$CurrentDomain="LDAP://"+ ([ADSI]"").distinguishedName
$domain=New-ObjectSystem.DirectoryServices.DirectoryEntry($CurrentDomain,$ADuser,$ADpass)
if ($domain.name-eq$null)
{
write-host"Authentication failed - please verify your username and password."-ForegroundColor Red
}
if ($domain.name-ne$null)
}while($domain.name-eq$null)
$Session=New-PSSession-ComputerName SERVER01 -Credential$cred
Invoke-Command-ScriptBlock {& C:\scripts\mainscript.ps1} -Session$Session
$ADadmin=read-host"Input administrative account to use"
$cred=Get-Credential$adadmin
$ADuser=$cred.username
$ADpass=$cred.GetNetworkCredential().password
$CurrentDomain="LDAP://"+ ([ADSI]"").distinguishedName
$domain=New-ObjectSystem.DirectoryServices.DirectoryEntry($CurrentDomain,$ADuser,$ADpass)
if ($domain.name-eq$null)
{
write-host"Authentication failed - please verify your username and password."-ForegroundColor Red
}
if ($domain.name-ne$null)
}while($domain.name-eq$null)
$Session=New-PSSession-ComputerName SERVER01 -Credential$cred
Invoke-Command-ScriptBlock {& C:\scripts\mainscript.ps1} -Session$Session
What i want this script to do is to pass the variables $Adadmin and $Cred to the mainscript.ps1 since that one also calls the same variables, and i don't want to have to authenticate twice.