Hi Rick,
You could have your script prompt for credentials. You can use the "GetNetworkCredentials" Method of the PSCredential object to enumerate the username and password. This will save you from having to hard code username and passwords or stop prying eyes of entering passwords in clear text (EG $password = Read-Host "Enter the password").
Param(
[Parameter(Mandatory=$False, HelpMessage="The credentials to authenticate as")]
[System.Management.Automation.PSCredential]$Credentials
)
#'------------------------------------------------------------------------------
#'Prompt for credentials if not provided.
#'------------------------------------------------------------------------------
If(-Not($Credentials)){
$username = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$Credentials = Get-Credential -Credential $username
}
#'------------------------------------------------------------------------------
#'Enumerate variables from credential object
#'------------------------------------------------------------------------------
$domain = $Credentials.GetNetworkCredential().Domain
$username = $Credentials.GetNetworkCredential().Username
$password = $Credentials.GetNetworkCredential().Password
If(-Not([String]::IsNullOrEmpty($domain))){
$user = "$domain\$username"
}Else{
$user = $username
}
If(([String]::IsNullOrEmpty($user)) -Or ([String]::IsNullOrEmpty($password))){
Write-Warning -Message "Credentials must be provided"
Break;
}
#'------------------------------------------------------------------------------
#'Set variables.
#'------------------------------------------------------------------------------
$plinkPath = "C:\Program Files\plink\plink.exe"
$fqdn = "ibmstorage.dns.name"
$command = "mkvdisk " + " -iogrp " + $sourceIOGrp + " -mdiskgrp " + $sourceMdiskGrp + " -name " + $sourceVdiskUName + " -size " + $sizeInMB + " -nofmtdisk -unit mb"
#'------------------------------------------------------------------------------
#'Call Putty Plink, to SSH into the IBM Storage System, and then run the command to create a vdisk:
#'------------------------------------------------------------------------------
& "$plinkPath" $fqdn -ssh -l $user -pw $password -batch "$command" > $exportPath\$uniqueVar-$sourceVdiskName-logfile.txt
#'------------------------------------------------------------------------------
You might also consider passing the other variables as input parameters so they aren't hard coded either. EG
Param(
[Parameter(Mandatory=$True, HelpMessage="The FQDN of the storage system")]
[String]$Fqdn,
[Parameter(Mandatory=$True, HelpMessage="The Source IO Group")]
[String]$SourceIOGrp,
[Parameter(Mandatory=$True, HelpMessage="The Source Mdisk Group")]
[String]$SourceMdiskGrp,
[Parameter(Mandatory=$True, HelpMessage="The Source Vdisk UName")]
[String]$SourceVdiskUName,
[Parameter(Mandatory=$True, HelpMessage="The disk size in MB")]
[Int]$SizeInMB,
[Parameter(Mandatory=$False, HelpMessage="The credentials to authenticate as")]
[System.Management.Automation.PSCredential]$Credentials
)
Then call your script from a powershell prompt, EG assuming you saved it as "ibm.ps1" in "C:\scripts\ibm" (The -Credentials paramater is optional, IE if you don't provide it it will be prompted for credentials)
PS C:\Scripts\IBM>ibm.ps1 -Fqdn $Fqdn -SourceIOGrp $SourceIOGrp -SourceMdiskGrp $SourceMdiskGrp -SourceVdiskUName $SourceVdiskUName -SizeInMB $sizeInMB
That should work fine if you don't mind being prompted to enter a username or password when you run the script. If you want to run the script multiple times, first create a credential object in your powershell session then pass it as a paramater so you are not prompted to enter credentials every time. EG
PS C:\Scripts\IBM>$Credentials = Get-Credential
PS C:\Scripts\IBM>ibm.ps1 -Fqdn $Fqdn -SourceIOGrp $SourceIOGrp -SourceMdiskGrp $SourceMdiskGrp -SourceVdiskUName $SourceVdiskUName -SizeInMB $sizeInMB -Credentials $Credentials
Hope that gives you some ideas.
/Matt
If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.