none
Placing this code in a scriptblock

    Question

  • Hi All.

    I am trying to place the code below in a sriptblock, not sure about the format.

    $root_drive = "D"
    	New-Partition  -DiskNumber 1 -DriveLetter $root_drive -Size 20GB
    	Format-Volume -DriveLetter $root_drive  -FileSystem NTFS -NewFileSystemLabel “D_” -Confirm:$false -Force
    

    In previous examples, I have seen

    $scriptblock = $ExecutionContext.InvokeCommand.NewScriptBlock("Remove-DnsServerResourceRecord -ZoneName $ZoneName -ComputerName $DCName -Name $HostName -RecordData $IPv4Address -RRType A -Force")
    


    • Edited by MrFlinstone Wednesday, May 15, 2019 10:53 AM
    Wednesday, May 15, 2019 10:51 AM

All replies

  • Do you mean something like this?
    $Scriptblock = { 
        $root_drive = "D"
        New-Partition  -DiskNumber 1 -DriveLetter $root_drive -Size 20GB
        Format-Volume -DriveLetter $root_drive  -FileSystem NTFS -NewFileSystemLabel “D_” -Confirm:$false -Force
    }


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    • Proposed as answer by jrvModerator Wednesday, May 15, 2019 4:44 PM
    Wednesday, May 15, 2019 10:53 AM
  • How do you then call this especially on a remote host ?

    Thanks.

    Wednesday, May 15, 2019 12:17 PM
  • With Invoke-Command.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Wednesday, May 15, 2019 12:30 PM
  • Thanks, how about passing parameters remotely ?
    Wednesday, May 15, 2019 1:44 PM
  • Sorry. It is far beyond the scope of a forum to teach you iteratively how to use Powershell for remote administration tasks. If you have a specific question about a particular piece of code you wrote you should post this code here and we will try to help you.

    And of course you are allowed to use your prefered search engine to do your own research.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Wednesday, May 15, 2019 2:06 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee



    Just do it.

    Monday, May 20, 2019 6:52 AM
    Moderator