How to call a variable from a Button to another.
hello powershleess guruuuusssss.
i have created below pws script using ps studio, , trying use variable "$svcname" on second button, empty. there way call variable second button'.
$buttongetservices_click={
#todo: place custom script here
$services = invoke-command -computername $boxcomputername.selecteditem -credential $global:farmcredential_ -scriptblock {get-service |select-object -property name, status, displayname}
load-datagridview -datagridview $datagridview1 -item $services
$svcname = $datagridview1.selectedcells[0].value --->> variable need
}
$btstartservice_click={
#todo: place custom script here
invoke-command -computername $boxcomputername.selecteditem -credential $global:farmcredential_ -scriptblock {
start-service $svcname ------> here variable nule.
$statussvr = get-service -name $svcname
}
$richtextbox2.text = $statussvr | out-string
}
here how using invoke:
$buttongetservices_click = { $iparams = @{ computername = $boxcomputername.selecteditem credential = $global:farmcredential_ scriptblock = {get-service} } $services = invoke-command @iparams load-datagridview -datagridview $datagridview1 -item $services } $btstartservice_click = { $iparams = @{ computername = $boxcomputername.selecteditem credential = $global:farmcredential_ scriptblock = {start-service $args[0] -passthru} argumentlist = $datagridview1.selectedcells[0].value } $service = invoke-command @iparams $richtextbox2.text = $service.status }
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment