INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Variable assignment?

Variable assignment?

(OP)
When I take the following and attempt to have parameters passed I end up with File Path errors.

$command = { dnscmd PS_Server /RecordDelete myzone myhost A 192.192.192.192 /f }

Invoke-Command -ComputerName PS_Server $command


Change that fails and produces errors -

$command = { dnscmd $PS_Server /RecordDelete $myzone $myhost A $IP /f }

Do I have to have nested quotes to be able to pass the parameters correctly?

Thank you for your assistance.


SteveR77

I.T. where a world of choas and confusion comes down to nothing but 1s and 0s.

RE: Variable assignment?

Give this a try:

CODE

$command = "dnscmd PS_Server /RecordDelete myzone myhost A 192.192.192.192 /f"
Invoke-Command -ComputerName PS_Server -ScriptBlock $command 


I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: Variable assignment?

(OP)
Mark,

Thanks!

The code should have been -

CODE -->

$command = "dnscmd $PS_Server /RecordDelete $myzone $myhost A 192.192.192.192 /f"
Invoke-Command -ComputerName $PS_Server -ScriptBlock $command 


However, the issue is not resolved. The error now is :

Invoke-Command : Cannot bind parameter 'ScriptBlock'. Cannot convert the "dnscmd $PS_Server /RecordDelete $myzone $myhost A 192.192.192.192 /f" value of type "System.String"
to type "System.Management.Automation.ScriptBlock".

My guess is the ScriptBlock is expecting arguments and is only seeing the single sting.


SteveR77

I.T. where a world of choas and confusion comes down to nothing but 1s and 0s.

RE: Variable assignment?

OK, so here is how you can pass arguments.

CODE --> PowerShell

$arg1 = "$PS_Server"
$arg2 = " /RecordDelete $myzone"
$arg3 = "$myhost"
$arg4 = "A"
$arg5 = "192.192.192.192"
$arg6 = "/f"
$args = @($arg1,$arg2,$arg3,$arg4,$arg5,$args6)

$command = "dnscmd"
Invoke-Command -ComputerName $PS_Server -ScriptBlock $command -ArgumentList $args 

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: Variable assignment?

A correction from the above posted code, I have an extra space in $arg2 inside the quotes. You will want to remove that to make it read:

CODE

$arg2 = "/RecordDelete $myzone" 

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: Variable assignment?

(OP)
Mark,

Here is what I did. I ended up dropping the code on the server and running it locally to avoid the conversion insanity.


CODE -->

#Setting of static variables
$PSServer = "mcaddnstdc01"
$DNSZone1 = "mclane.mclaneco.com"
$DNSZone2 = "mclaneco.com"
$hstname = "vcacdnstest"
$IP = "10.40.27.117"


# Delete mclane.mclaneco.com DNS entry
$cmdDelete = "dnscmd  $PSServer /RecordDelete $DNSZone1 $hstname A $IP /f"
Invoke-Expression $cmdDelete

# Add mclane.com DNS entry
$cmdAdd = "dnscmd $PSServer /RecordAdd $DNSZone2 $hstname A $IP"
Invoke-Expression $cmdAdd 


Thanks again for all your help with this.

Make it a great day.


Steven

I.T. where a world of choas and confusion comes down to nothing but 1s and 0s.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close