Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable assignment? 1

Status
Not open for further replies.

SteveR77

Programmer
Sep 18, 2000
813
US
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.
 
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
Work SMARTER not HARDER.
 
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.
 
OK, so here is how you can pass arguments.

Code:
$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
Work SMARTER not HARDER.
 
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
Work SMARTER not HARDER.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top