VMware Cloud Community
vlife201110141
Enthusiast
Enthusiast
Jump to solution

Covert date system.date format to string

Hello,

I have a scheduled task which will run two days a week which clones a vm. I would like to add dayof week to end of the vm name lets say for Monday and Thursday

$_this.CloneVM_Task($folder, "Bulut_Productive_MondayClone", $spec)

$_this.CloneVM_Task($folder, "Bulut_Productive_ThursdayClone", $spec)

To resolve this issue

$date = Get-Date

$dayofweek = $date.DayOfWeek

the type is [system.datetime] but i need to convert  [system.datetime] format to [string] to add end of vmname

$dayofweek | out-string

not working any idea to fix this part.

Thanks,

-------------------------------------------------------------------------------------------------

Add-PSSnapin vmware.VimAutomation.Core
$emailFrom = "ABC@xxx.com"
$emailTo = "ABC@xxx.com"
$smtpServer = "x.x.x.x"
$body = "xxx"
$subject = "xxx"

connect-VIServer -server "xxx" -user "xxx" -password "xxx"

# ------- Destroy_Task -------

#$destroyit = Get-View -ViewType VirtualMachine -Filter @{"Name" = "Bulut_Productive_.MondayClone"}
#$destroyit.Destroy_Task()

# ------- RemoveAllSnapshots_Task -------

$_this = Get-View -ViewType VirtualMachine -Filter @{"Name" = "Bulut_Productive"}
$_this.RemoveAllSnapshots_Task($true)

# ------- CloneVM_Task -------

$folder = New-Object VMware.Vim.ManagedObjectReference
$folder.type = "Folder"
$folder.Value = "group-v484"

$spec = New-Object VMware.Vim.VirtualMachineCloneSpec
$spec.location = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.location.datastore = New-Object VMware.Vim.ManagedObjectReference
$spec.location.datastore.type = "Datastore"
$spec.location.datastore.Value = "datastore-62888"
$spec.location.pool = New-Object VMware.Vim.ManagedObjectReference
$spec.location.pool.type = "ResourcePool"
$spec.location.pool.Value = "resgroup-29"
$spec.location.disk = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator[] (1)
$spec.location.disk[0] = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator
$spec.location.disk[0].diskId = 2000
$spec.location.disk[0].datastore = New-Object VMware.Vim.ManagedObjectReference
$spec.location.disk[0].datastore.type = "Datastore"
$spec.location.disk[0].datastore.Value = "datastore-62888"
$spec.location.disk[0].diskBackingInfo = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo
$spec.location.disk[0].diskBackingInfo.fileName = ""
$spec.location.disk[0].diskBackingInfo.diskMode = ""
$spec.template = $false
$spec.powerOn = $false

$_this = Get-View -ViewType VirtualMachine -Filter @{"Name" = "Bulut_Productive"}
$_this.CloneVM_Task($folder, "Bulut_Productive_MondayClone", $spec)

$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)

0 Kudos
1 Solution

Accepted Solutions
vlife201110141
Enthusiast
Enthusiast
Jump to solution

[string]::Concat(“Bulut_Productive_“, $date.dayofweek, "_Clone“)

this resolves what I need thanks anyway

View solution in original post

0 Kudos
1 Reply
vlife201110141
Enthusiast
Enthusiast
Jump to solution

[string]::Concat(“Bulut_Productive_“, $date.dayofweek, "_Clone“)

this resolves what I need thanks anyway

0 Kudos