Questions tagged [scriptblock]

Single unit of operation of expression and statements.

Multiple expressions or statements which make up a single unit of operations. The block can accept return values and arguments. Usually found in a statement list in braces such as {<list of statements>}.

154 questions
0
votes
1 answer

Powershell class inside script block for Invoke-Command

I've faced up with a problem to execute powershell class methods inside a scriptblock passed to invoke-command. Let's start with some examples FooClass.psm1 class Foo { static [string]Func() { return "bar" …
0
votes
0 answers

Trying to run a script block locally as admin using powershell

I am trying to write a powershell script that runs a specific code block as a domain admin and moves a computer to a specific OU. If I run it as a domain admin, it works fine, but the problem is it usually runs it as a local admin; which obviously…
0
votes
1 answer

Powershell: Passing Get-ADGroup collection to background job, missing various property values

If this has been answered please kindly point me to the solution, however, at this time I am unable to find a answer to this in the existing posts. I am currently working with background jobs in powershell as to breakup a heavy process into parallel…
CodePoet
  • 3
  • 2
0
votes
0 answers

Powershell start-job -scriptblock equivalent in Java error with Callable / Future

Hey all new to Powershell so here goes. I am wanting to take the code below and convert it into java so that I do not have to run a separate Powershell script outside my program when its running. [string] $wspaceDir =…
StealthRT
  • 10,108
  • 40
  • 183
  • 342
0
votes
1 answer

How to call a Scriptblock as a function parameter in Powershell

I would like to have a function to run different ScriptBlocks. So, I need to use my Scriptblock as the parameter of the function. It does not work. For example. This function returns the ScriptBlock as a string. function Run_Scriptblock($SB) { …
Alin
  • 350
  • 2
  • 13
0
votes
1 answer

Expression on Column Addition To Object Receives Error Hash Literal Incomplete

Why am I able to do a command outside the script block, but not inside it? My final goal is to sort a directory listing based on predefined categories. The code creates a dynamic object from the directory listing and adds two columns. The first…
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
0
votes
1 answer

Unable to Unzip Folder when invoked on a remote PC

I'm Attempting to Unzip A folder located on a shared drive to the root of C:\ on a remote PC but keep getting errors, how do i correct this Powershell? $Computers = "LN-T48-PF11BL57" Invoke-Command -Computername $Computers -ScriptBlock { …
Khalifa96
  • 47
  • 2
  • 10
0
votes
1 answer

Custom PowerShell cmdlet with a ScriptBlock in a hashtable

I have a custom Powershell Cmdlet in C#, all works fine. The one parameter is a HashTable. How can I use a ScriptBlock in that parameter? When I set the parameter to @{file={$_.Identity}}, I want to get a pipeline object with Identity property in…
0
votes
0 answers

Sharepoint (office 365) online: HTML Script error

While trying to open a HTML page, scripts get blocked. By default, the dynamic generated is blocking the script to run. How to overcome this and allow the script to run. The purpose of creating the HTML page is to render in multiple CEWP. Please…
0
votes
0 answers

Powershell -scriptblock Job monitoring and orchestration

I have several jobs that I would like to orchestrate and monitor in PowerShell. All these are -scriptblock Jobs so each are running in their own environment. $Job_List = JobNum1, JobNum2, JobNum3, JobNum4, JobNum5 PS > Get-Job Id Name …
Philippe
  • 103
  • 1
  • 1
  • 8
0
votes
1 answer

Execute Powershell code on remote computer and then use result on local computer

I know, that to execute code on remote computer, I must use -ArgumentList and param to pass variables to remote host. Can anyone hint me, how to execute code on remote computer, and then use result on local computer? My code, to determine free space…
Vasyl Stepulo
  • 1,493
  • 1
  • 23
  • 43
0
votes
2 answers

Why does an argument passed into a script block fail to work?

Full disclosure: My problem may be based on a incomplete understanding of the Citrix PowerShell module for Xen Desktop. I have the following script block. It's called in a loop, once for each VM in a list. I'm using PowerShell Jobs because I want to…
VA systems engineer
  • 2,856
  • 2
  • 14
  • 38
0
votes
1 answer

PowerShell - send variable via Invoke-Command

I have 3 Windows 2016 servers and some routine task I want to automate. I'm newbie in PowerShell, so I spent a lot of time looking for answer in StackOverflow and "googling". My task is to backup some files via 7zip on remote server. There are is a…
0
votes
0 answers

How to parameterise a command invocation inside a script block?

I am trying to write a PowerShell script with a Script Block that is to be passed to Invoke-Command. The script block needs to invoke an executable whose path is determined by a PowerShell variable ($bar in this example) However, when I try to do…
jonseymour
  • 1,006
  • 1
  • 12
  • 22
0
votes
1 answer

Trying to code a function which takes a scriptblock with params and argument list, edits that scriptblock and then runs invoke-command

I am editing a function which it will invoke a command directly on the VM. The issue I keep running into is if someone passes a function declaration as a scriptblock, I get and error when calling create, because params() is not at the top of the…
Mark
  • 11
  • 1
  • 3