Jump to content
    • Forum width %
Перед созданием темы - убедитесь, что вы создаёте её в правильном разделе.
Темы оформленные не по образцу шаблона - не подлежат публикации на форуме.

Создание скрипта PowerShell


Go to solution Solved by Misferado,

Recommended Posts

The essence and description of your problem:

у меня стоит задача создания и настройки скрипта на создание у пользователя VPN подключения, спустя много боли и страданий я кое-как написал его, но есть 3 момента:

1. что бы занести данные под конкретного пользователя надо лезть в код, хотелось бы привязать переменные к txt

2. часть кода ctrl+c\ctrl+v из инета, хотелось бы понять что я скопировал)))

3. можно как-то скрыть сам скрипт и txt-файл в архиве, что бы пользователь их не видел? а в идеале ещё и запретить их открывать, что бы он не смог оттуда вытащить учётные данные 


When (after) the problem appeared:

после постановки задачи


Your actions to solve the problem:

код из ps:

If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))

{   
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
Add-VpnConnection -Name "VPN" -ServerAddress "0.0.0.0" -TunnelType "L2tp" -Force -EncryptionLevel "Optional" -AuthenticationMethod "MSChapv2" -SplitTunneling $true -RememberCredential -PassThru
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Install-Module -Name VPNCredentialsHelper
$user = "UserName"
$plainpass = "UserPassword"
Set-VpnConnectionUserNamePassword -connectionname "VPN" -username $user -password $plainpass -PassThru
Add-VpnConnectionRoute -Name "VPN" -DestinationPrefix 1.1.1.0/24
Add-VpnConnectionRoute -Name "VPN" -DestinationPrefix 2.2.2.0/24
rasdial "VPN"
ping 1.1.1.1
ping 2.2.2.1


PC components:

Комплектующие не требуются (примечание администратора)


Additional description:

код bat-файла, запускающего скрипт:

SetLocal EnableExtensions

set "ps=" & for %%X in (powerShell.exe) do set "ps=%%~$PATH:X"
if not defined ps set "ps=%systemRoot%\system32\windowsPowerShell\v1.0\powerShell.exe"

For /F "UseBackQ delims=" %%a in (`"cmd /c "
  "%ps%" -ExecutionPolicy ByPass -NoProfile -file "C:\users\%username%\downloads\VPN_FullSetup\VPN_FullSetup_V5.0.0.2.ps1"
""`) do (
  echo %%a
)


Operating system: Windows 10
Link to comment
  • A+ changed the title to Создание скрипта PowerShell
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Dear guest, before registering or creating a topic - read the rules of the forum - Guidelines