Please help - embed or pass the credentials

Nov 20, 2009 at 6:23 PM


I have a powershell script that performs a P2V (convert physical server to virtual) using Virtual Machine Manager cmdlets.
The script runs fine if I run it from powershell and I enter my credentials when prompted.
I want to be able to schedule the script using Task Scheduler but have not figured out a way
to embed or pass the credentials.  Please  heip.

Thanks

Coordinator
Nov 24, 2009 at 3:32 PM

You should be able to specify the credentials as part of a scheduled job. Don't embed them in the script.

Nov 24, 2009 at 9:44 PM

Hi, I try to build my p2v script  base on Virtual Machine Manager p2v  script

and try to scedsule  to run this script  every  week automatically

Coordinator
Nov 26, 2009 at 1:01 AM

You do understand that this library has no connection with SCVMM ?  :-)

If you can post the lines of script which prompt for the password I can look at it and see if there is a way to embed the credentials, but you do realise (a) this is a bad thing to from a security point of view, and (b) when your password changes the script will need to change.

Nov 30, 2009 at 5:08 PM
Edited Nov 30, 2009 at 11:57 PM

Hi,  yes I knew this are security risk but we need to do scedgule script  p2v  of one of system ...

Thanks.

 

VMHost = Get-VMHost -VMMServer localhost | where {$_.Name -eq "System10.newdom.com"}
$MachineConfig = Get-MachineConfig -VMMServer localhost | where {$_.Name -eq "10.15.14.46"}

New-P2V -VMMServer localhost -VMHost $VMHost -RunAsynchronously -JobGroup 61d4ebed-7990-4666-8185-7cb252f0e7ea -SourceNetworkConnectionID "00:15:5D:73:43:00" -PhysicalAddress "00:15:5D:73:43:00" -PhysicalAddressType Static -NoConnection -MachineConfig $MachineConfig

$VMHost = Get-VMHost -VMMServer localhost | where {$_.Name -eq "System10.newdom.com"}
$MachineConfig = Get-MachineConfig -VMMServer localhost | where {$_.Name -eq "10.15.14.46"}

New-P2V -VMMServer localhost -VMHost $VMHost -RunAsynchronously -JobGroup 61d4ebed-7990-4666-8185-7cb252f0e7ea -VolumeDeviceID "\\?\Volume{51e7a307-c8b2-11de-9ec5-806e6f6e6963}\" -Dynamic -IDE -Bus 0 -LUN 0 -MachineConfig $MachineConfig

$VMHost = Get-VMHost -VMMServer localhost | where {$_.Name -eq "System10.newdom.com"}
$MachineConfig = Get-MachineConfig -VMMServer localhost | where {$_.Name -eq "10.15.14.46"}

New-P2V -VMMServer localhost -VMHost $VMHost -RunAsynchronously -JobGroup 61d4ebed-7990-4666-8185-7cb252f0e7ea -VolumeDeviceID "C" -Dynamic -IDE -Bus 0 -LUN 1 -MachineConfig $MachineConfig

$Credential = get-credential
$VMHost = Get-VMHost -VMMServer localhost | where {$_.Name -eq "System10.newdom.com"}
$MachineConfig = Get-MachineConfig -VMMServer localhost | where {$_.Name -eq "10.15.14.46"}

New-P2V -Credential $Credential -VMMServer localhost -VMHost $VMHost -Path "D:\Hyper-V" -Owner "newdom\Alex" -RunAsynchronously -JobGroup 61d4ebed-7990-4666-8185-7cb252f0e7ea -Trigger -Name "Win1" -MachineConfig $MachineConfig -CPUCount 1 -MemoryMB 1024 -RunAsSystem -StartAction NeverAutoTurnOnVM -StopAction SaveVM

Coordinator
Dec 8, 2009 at 11:29 PM

It looks like you need to create the credential object  and this should work.

$credential = New-Object System.Management.Automation.PSCredential -ArgumentList "domain\user",(ConvertTo-SecureString -AsPlainText -force -string "Password")