Get IP Address Powershell
Posed on 2008-05-14 20:20:48
Author: Gareth Bennett
You have just logged into your VPN and you have forgotten your IP address for your computer, Powershell to the rescue!
To find your IP address:
[System.Net.Dns]::GetHostByName("YourComputerName")
You can also use:
[System.Net.Dns]::GetHostAddresses("YourIPAddress")
Or
[System.Net.Dns]::GetHostAddresses("www.YourURL")
To gain useful information about an address
Comments on Get IP Address Powershell (0)
List DLL files Powershell
Posed on 2008-04-30 20:19:04
Author: Gareth Bennett
Recently I needed to find all DLL files in the Windows System32 folder. To do this I would need to recurse though any sub-folder that may be present in the System32 folder. To finish I needed to output all data to a flat file for later inspection.
Here is a new script:-
########################################################
# Powershell script, list DLL files in system32 folder #
########################################################
$objDir = get-childitem "C:\windows\system32" *.dll -recurse -force
$objFiles = $objDir | where {$_.attributes -ne "Directory"}
foreach ($objFile in $objFiles) {
$newfile = $objFile.fullname
$newfile | out-File "c:\dllfiles.txt" -append
}
Comments on List DLL files Powershell (0)
Running PowerShell Scripts
Posed on 2008-04-01 13:02:41
Author: Gareth Bennett
The mistake Microsoft made with VBScript is the ability to execute scripts without any security policies.
PowerShell, is all signing and dancing when it comes to security; but how do you run scripts with all these new security policies? The answer is that there are many different ways to run scripts, but the one I am going to cover in this article is one of the easiest and good for quick development. Signing Certificates to run scripts is quite a major process so I am not going to cover that here.
Execution Policy
One thing with PowerShell, it is easy to display the help in the Console. I prefer to output the help to a text file
Get-Help Set-ExecutionPolicy -full | Out-File "C:ExePolicy.wri"
You will notice I am outputting the full documentation (-full) for setting the ExecutionPolicy. And outputting the file as a Wordpad document (wri). I don't like using Notepad as there is a limit to the amount of data it can hold; as PowerShell is currently a Microsoft centric environment this seems appropriate.
Set-Execution Policy (Syntax)
SYNTAX
Set-ExecutionPolicy [-executionPolicy] {Unrestricted | RemoteSigned | AllSigned | Restricted | Default} [
-whatIf] [-confirm] [CommonParameters]
We are going to use the [Unrestricted] Property to execute are scripts.
Set-ExecutionPolicy Unrestricted
To finish off we can see what the ExecutionPolicy has been set to.
Get-ExecutionPolicy
Once this command has been executed you should be presented with the Unrestricted in the Console, see below:-

Now you have set the ExecutionPolicy to unrestricted you will be able to execute any script by calling it from the console or adding PowerShell ".yourscript.ps1" to a batch-file.
Comments on Running PowerShell Scripts (0)
