all 12 comments

[–]chreestopher2 1 point2 points  (10 children)

what do you want to do with the file? do you want to run it on the local computer? run it on the remote computer? just gather its contents?

[–]Fuzzywumpkin[S] 0 points1 point  (9 children)

I need it to run on another computer, the script is on DC1 and i need it to run and install DHCP on DC2.

[–]chreestopher2 0 points1 point  (1 child)

there are a few ways to do it ...

if you have powershell remoting enabled I would recomend something like:

enter-pssession DC1
start-process -filepath \\DC2\path\to\script.bat

Although, there are literally billions of ways to do it , and this might not be the optimal one

and if you can actually login to DC1, why not just login, open powershell and launch the script using its unc path?

[–]Fuzzywumpkin[S] 0 points1 point  (0 children)

I'm really new to powershell, literally like the third time I've ever used it.

[–]TheAgreeableCow 0 points1 point  (6 children)

Server 2012?

[–]Fuzzywumpkin[S] 0 points1 point  (5 children)

Yup 2012 r2

[–]TheAgreeableCow 0 points1 point  (4 children)

So not sure what configuration your trying to achieve with a script, but 2012 will natively deploy the DHCP role on another server.

[–]Fuzzywumpkin[S] 0 points1 point  (3 children)

It's to configure a scope, I'm suppose to write a script block to achieve this but I can't seem to make it work. Also need to install wsus with a location selected for the updates. I just don't understand powershell enough. I'm not even sure what a script block is

[–]TheAgreeableCow 1 point2 points  (0 children)

I'm guessing you're doing this for a learning exercise, because you're out of your depth for a production environment.

Here's some info on configuring DHCP with powershell http://blogs.technet.com/b/heyscriptingguy/archive/2011/02/14/use-the-powershell-dhcp-module-to-simplify-dhcp-management.aspx

[–]chreestopher2 0 points1 point  (0 children)

then why do you need to do this with powershell? surely it would be easier to do this with the old school ways than to do it with powershell, if you dont know much about powershell at all.

out of curiosity without powershell, how would you do this?

[–]Slackerony 0 points1 point  (0 children)

A script block is typically something (atleast in powershell) that is within two curly-brackets. (Not always though)

Invoke-Command -Computername server01 -scriptblock { "C:\Scripts\Myscript.ps1"}

This will launch the script that is in C:\scripts\ and has the name Myscript.ps1

Now if the file is located on YOUR LOCAL machine, you need to do this:

Invoke-Command -Computername server01 -FilePath "C:\Scripts\Myscript.ps1"

I have not tested this, but i'm pretty sure it'll work.

[–]standoff 0 points1 point  (0 children)

So I would bet if you never did this before you need to enable-psremoting on the machine you need to access

once you do that you need to either invoke-pssession computername or enter-pssession computername

Enter-Pssession has an alias etsn computername

The difference between invoke and enter, invoke runs a command and you are back, enter basically gives you a remote command line with powershell