I'd like to create a script that will toggle between setting the DNS settings of my wireless card between automatic selection and a particular IP (openDNS).
Can this be done, and if so what should I look in to?
Thanks!
I personally would look at Powershell to do this. I found a post on how to change your ip settings in a one liner.
Get-WmiObject -class win32_networkadapterconfiguration | where-object -filterscript { $_.IPEnabled -eq ‘True’ -and $_.ServiceName -eq ‘E100B’ } | foreach-object -process { $_.EnableStatic(’192.168.1.200′,’255.255.0.0′) }
Author of this code's original post
I would use netsh (google for it)
Thanks for the link back.
Here is some info that may be helpful:
Still Very Much Alive and Kicking - netsh
Tutorial PowerShell v3: TCP/IPv4 (and IPv6) Network Basics - Part I and Part II
Related
I need to get all installed applications and its details in a Windows device using shell commands. I tried using
Get-appxpackage
Get-WmiObject
wmic
Apps that were installed manually seems to be missing in the list. Please help by providing a better method.
An alternative can be to query the registry like this for example:
# HKLM - Local Machine
$InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
foreach($obj in $InstalledSoftware){write-host $obj.GetValue('DisplayName') -NoNewline; write-host " - " -NoNewline; write-host $obj.GetValue('DisplayVersion')}
# HKCU - Current User
InstalledSoftware = Get-ChildItem "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
foreach($obj in $InstalledSoftware){write-host $obj.GetValue('DisplayName') -NoNewline; write-host " - " -NoNewline; write-host $obj.GetValue('DisplayVersion')}
Check this page out for more:
https://www.codetwo.com/admins-blog/how-to-check-installed-software-version/
Tip! Browse these locations in the registry manually before you dig in as it will help you see the structure and understand what properties are available. If the information you're seeking is not there, you might just ditch this suggestion.
For Windows 64-bit and 32-bit apps use
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table > C:\ws\apps.txt
the C:\ws\apps.txt need to be adjusted by you, to your output path.
I found the idea here, Social MS
I got a client who asked me to find all of his Dhcp and DNS servers with some additional info like DC servers and operationsystem
so i decided to try sharpen my powershell skills but im still new to this so i wrote this script but i guess something is still missing because it doesnt work
EDIT: i managed to find a way to get the info i want which is the OS but it gets me back ALL the servers in the company
$servers = get-dhcpserverindc
foreach($server in $Servers){
get-adcomputer -filter {Operatinsytem -like "*windows server*"} -properties
Operatingsystem | sort name | format-table name,Operatinsytem
}
This is not too tricky. First off, you connect to a machine with the RSAT Tools installed, like an admin server, jump box, or Domain Controller, and get a list of all DHCP Servers.
$DHCPServers = Get-DhcpServerInDC
Then we use PowerShell's built in looping logic to step through each server, and check for the OS info you need.
ForEach ($DHCPServer in $DHCPServers){
$OSInfo = Get-CIMInstance -ComputerName $DHCPServer.DnsName -ClassName Win32_OperatingSystem
}
Finally, we'll modify this above to return the info you're looking for, namely the IP Address, Name, and OS Version
ForEach ($DHCPServer in $DHCPServers){
$OSInfo = Get-CIMInstance -ComputerName $DHCPServer.DnsName -ClassName Win32_OperatingSystem
[pscustomobject]#{
ServerName = $DHCPServer.DnsName;
IPAddress=$DHCPServer.IpAddress;
OS=$OSInfo.Caption
}
}
ServerName IPAddress OS
---------- --------- --
dc2016 192.168.10.1 Microsoft Windows Server 2016 Standard
From there, you can store it in a variable, make it a spreadsheet, do whatever you need to do.
Hope this helps.
If this isn't working, make sure you have enabled PowerShell Remoting first.
I already knew how to get all network adaptors names, but I can't tell the difference between normally using and not identified
By using
netsh interface ip show interfaces
or other commands ,you may get all adaptors names.
The necessary information can be obtained using the Win32_NetworkAdapter class.For example:
Get-CimInstance -ClassName Win32_NetworkAdapter -Filter #'
NetConnectionID = "Local Area Connection" AND
NetConnectionStatus=2 AND NetEnabled = True AND PhysicalAdapter = True
'# | Format-List *
The Get-WmiObject cmdlet can also be used, but starting in PowerShell 3.0, it has been superseded by Get-CimInstance.Starting with Windows 8, you can use the Get-NetAdapter cmdlet.
I have windows domain network, i have about 3000 hosts in there. I would like to just check the info which of those hosts having specified technical user account in their local admin groups. I am not that great at power shell, though I know the base things.
I belive that I have to make a list of all hosts across several subnets I have and then run a script that will try to log on those hosts with looking account credentials.
What could be the best solution?
There is a very detailed post on TechNet about listing all computers in domain.
And here's the WMI query part (PowerShell, $aComputerList is a list of computer names):
foreach ($sComputerName in $aComputerList) {
$sUserPattern = 'Win32_UserAccount.Domain="domainname",Name="username"'
$sGroupPattern = 'Win32_Group.Domain="{0}",Name="Administrators"' -f $sComputerName
$oResult = Get-WmiObject -ComputerName $sComputerName -Class Win32_GroupUser | `
Where-Object {
($_.groupcomponent -match $sGroupPattern) -and `
($_.partcomponent -match $sUserPattern)
}
[Bool]$oResult
}
The hard part is that some computers probably won't be reachable (if they're turned off for instance). So you'll need to run your script several times and remove computers from the list as you get responses from them.
Does anybody know if there is a Windows API to return the location of the hiberfil.sys ?
Many thanks
Hiberfil.sys is created when you enable hibernation and have hibernated your computer at least once. Its location can be determined like any other file: by directing the OS to search for it. Its usual location is in the root of your system drive, which is usually C:. This working powershell script was found here. See the link for the full script, but this is the core:
gwmi cim_datafile -filter "path='\\'" | ? {$_.name -match 'hiberfil.sys'} or
gwmi -Query "Associators of {Win32_Directory.Name='C:\'} Where ResultClass=CIM_DataFile" | ? {$_.name -match 'hiberfil.sys'}
Also helpful, Karl. E. Peterson's API reference:
http://vb.mvps.org/samples/apixref.asp
He also has made available for download some sample code, zipped up. Hope this helps...