run powershell script as administrator?

Soldato
Joined
29 Jul 2003
Posts
7,681
hi

got a wee powershell script that enable IP to DHCP and its working when i copy the script to powershell with adminsitrator

i would like to make a script instead but it wouldnt let me run it.

$networkConfig = Get-WmiObject Win32_NetworkAdapterConfiguration -filter "ipenabled = 'true'"
$networkConfig.EnableDHCP()
$networkConfig.SetDNSServerSearchOrder()

ipconfig /registerdns

"*****************************************" | Out-File C:\Windows\COMPANY-staticIP.txt -Append
get-date | Out-File C:\Windows\COMPANY-staticIP.txt -Append
ipconfig /all | Out-File C:\Windows\COMPANY-staticIP.txt -Append

how to run the .ps1 with administrator? there is no option to right click -select run as adminstrator

thanks

:)
 
oops you are right.

got the administator option working now but the script is not doing anything, it doesnt set the IP to dhcp. which it does works when i copy/paste the script to powershell (run > cmd right click run as adminstrator)
 
Code:
PS C:\Users\infowp\Desktop> C:\Users\infowp\Desktop\dhcp3.ps1
File C:\Users\infowp\Desktop\dhcp3.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
    + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnauthorizedAccess

PS C:\Users\infowp\Desktop>

got this error message
 
PS C:\WINDOWS\system32> Get-ExecutionPolicy
Restricted
PS C:\WINDOWS\system32> Set-ExecutionPolicy unrestricted

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All Suspend [?] Help (default is "N"):
 
thats more work than change the IP to DHCP via the control panel.

shame there is no real quick way for this.

but thanks guys :)
 
hi vince thanks again

i dont have the access to DC from home, will have to wait till monday

im confused by what you said "But you can remove the fixed address from the scope of dhcp"

every PCs are issued a static IP address by manual input rather than they have been issued a static IP by deployment.

edit: approx 2300 PC's at 5 centres to be move to DHCP. im responsible for 1 centre with approx 470 PC's
 
thanks for the post

the network manager designed the network and configured the vlans for each floors and 3 domains, wifi too. (wifi devices are on DHCP). all PC's are issued with static IP corresponding to the hostname and floor.

no problem with networking at all. recently the manager have asked us to move all PC's from static to DHCP....DHCP leasing are already setup ready for the PCs to be taken off the static IP

i just need a very simple way to get the PC's on DHCP. if it was that simple, he would do it via the group policy.

edit: its not my role to dealing with the networking. i'm just an IT techie that responsible for a site with 470 PC's. i have access to the DC. and group policies too.
 
Back
Top Bottom