Search code examples
powershellbatch-filedrive

Running PS1 file from batch file, same folder on thumb drive


Admittedly I'm no scripter. I piece together what already works but trying to learn.

I have a script that does a lot of the manual labor for setting up a scan user for myself and our techs. Here is a small portion of it written as a batch file. At the end before the pause I want to call a PowerShell to show what the Network type is, not to change it. At least not at this time. I did remove alot of the extra from the file to save space. Both the batch file and the PS1 file will be in the same folder on a thumb drive.

The nettype.ps1 file just has:

get-netconnectionprofile
pause

The pause of course is so the tech can see the network type.

Hope someone has a simple solution. I did look here and other websites. I may not be using the right terminology in my search or understanding what I need done.

net user Scans Scanner1 /add
net localgroup administrators Scans /add
wmic UserAccount where Name='Scans' set PasswordExpires=False
md C:\Scans
@echo off

NET SHARE Scans=C:\Scans /Grant:Scans,Full
ICACLS "C:\Scans" /Grant Scans:(OI)(CI)(F) /t /c
ICACLS "C:\Scans" /Grant Everyone:(OI)(CI)(F) /t /c
netsh advfirewall firewall set rule group="Network Discovery" new enable=Yes
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes
PowerShell.exe -File "nettype.ps1"
pause

Solution

  • If that is all you have inside your script, don't run it as a script, delete it and just run the command directly in your :

    "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -Command "Get-NetConnectionProfile"
    

    Which could be probably be shortened to:

    PowerShell Get-NetConnectionProfile