Workflows

Hey all, i was hoping someone could explain some stuff to me. Now I’m no pro with powershell, but I really want to get better at it. And unfortunately I don’t really have a strong background in programming. So some of the way that programming stuff works doesnt really make sense.

Anyway, i was kind of thinking it’d be cool to do something on the lines of, install hyper-v, name computer, add to domain, and maybe add VMs to the host. But the scripts would need it to continue through reboot.

Thats where i found workflows So i figured id give it a try.

workflow hyperv{
param([String]$name)
Sequence{
$name = 'Node5'
Rename-computer -NewName $name -Force -Passthru
Restart-Computer -Wait

}

}

I can get the first part to run ok and rename the computer, the adding to the domain part doesnt work so much. How would i go about doing that?

Also i had some random questions and im hoping that a better understanding of certain parts will make it all make more sense for me…

  • What is the point of adding the Param([String]) in there if i set the variable to something anyway? Is this field mainly for input?

  • I get that sequence does things in order, while parallel does stuff however, if i wanted to do more than one thing, like install hyper-v, restart, rename, restart, add to domain, restart… Would i need more than one Sequence block?

  • Same with the inline-script, what is the exact purpose of that besides executing single portions?

Anyway, thanks in advance for whoever reads this, hopefully most of it made sense.

I haven’t personally done anything with Workflows, but Desired State Configuration is becoming the preferred way to accomplish this sort of task, so long as you meet all of its minimum requirements. (Only operating systems compatible with WMF / PowerShell 4.0 can leverage DSC, whereas workflows can be used with WMF / PowerShell 3.0. The differences are that 3.0 is supported on Windows Server 2008 SP2, Windows 8, and Windows Server 2012, and 4.0 is not; you would have to upgrade to 2008 R2 SP1, 8.1, or 2012 R2.)