locked
Elevate Powershell dont know network RRS feed

  • Question

  • Hi,

    I have this code but need some help to make it better.

    # carrega todos os scripts para conhercer as suas funcoes
    Write-Host 'A CARREGAR OS SCRIPTS DESENVOLVIDOS'
    Get-ChildItem "\\servidor\scripts$\Run\*.ps1" | %{Import-Module $_ -Force}
    
    #Write-Host 'A DORMIR 5 SEG'
    #Start-Sleep 5
    
    Set-Variable -Name pcname -Option None
    
    if ($env:computername -eq "PC_Template")
    {
        #devia carregar uma nova janela interactiva com o script set-novoclone a correr
        Write-host 'Correr script para novo clone'
        Start-Sleep 1
        Start-Process powershell -ArgumentList 'Get-ChildItem "\\servidor\scripts$\Run\*.ps1" | %{Import-Module $_ -Force};  Set-Clone; Read-Host' -verb RunAs
    }
    else
    {
        # Define o wallpaper actual
        Write-Host 'A DEFENIR WALLPAPER'
        #Build-TextOverlay
        Set-Wallpaper background.jpg
    
        #aviso para encerramento do espaço
        write-host Script de aviso de fecho em backgroud
        Start-Job -ScriptBlock {Get-FechoSala} -Name "Fecho"
    }

    This line below works great and when i call the function Set-Wallpaper it works.

    Get-ChildItem "\\servidor\scripts$\Run\*.ps1" | %{Import-Module $_ -Force}

    But when i run the script when it pass here

    Start-Process powershell -ArgumentList 'Get-ChildItem "\\servidor\scripts$\Run\*.ps1" | %{Import-Module $_ -Force};  Set-Clone; Read-Host' -verb RunAs

    it do what it should but the new windows don't know the network link and the windows close with an error.

    Please help me to solve this!


    TcoUpLoad (Vb6 and VbNet | starting learning C# and LINQ)

    Tuesday, February 27, 2018 6:03 PM

Answers

  • $arglist = @(
        '-Command', 
        '"Get-ChildItem \\servidor\scripts$\Run\*.ps1 | %{Import-Module $_ -Force};  Set-Clone; Read-Host"'
    )
    Start-Process powershell -ArgumentList $arglist -verb RunAs


    \_(ツ)_/

    • Marked as answer by Tcomsn Tuesday, February 27, 2018 6:11 PM
    Tuesday, February 27, 2018 6:09 PM

All replies

  • $arglist = @(
        '-Command', 
        '"Get-ChildItem \\servidor\scripts$\Run\*.ps1 | %{Import-Module $_ -Force};  Set-Clone; Read-Host"'
    )
    Start-Process powershell -ArgumentList $arglist -verb RunAs


    \_(ツ)_/

    • Marked as answer by Tcomsn Tuesday, February 27, 2018 6:11 PM
    Tuesday, February 27, 2018 6:09 PM
  • Thanks a LOT.

    TcoUpLoad (Vb6 and VbNet | starting learning C# and LINQ)

    Tuesday, February 27, 2018 6:11 PM