Your best source of information and news about secrets, BIOS and winvista on the internet

Vista ARTICLES TOP 50 Spyware Virus Vista SOFT Vista HELP

PowerShell

You are currently browsing the articles from MS Windows Vista Compatible Software matching the category PowerShell.

Reboot a computer remotely with WMI and PowerShell

One of the trickiest things to do when working with computes remotely is reboot them. We also have to make sure that the computers don’t have any bios issues that can cause them to not restart. Many times we can’t even get logged on if their Terminal Services access is shut off. With this trick you can reboot a server with ease, even one that doesn’t have PowerShell installed.

 

To do this first we get on a computer that does have PowerShell. At the PowerShell prompt, try:

PS C:\> $your_server = gwmi win32_operatingsystem -computer yourservername

If you follow best practices and do not run under a domain admin account, (or an account that is local admin on all your servers) Then you should see an error like this:

Now we want to be able to shutdown a computer, but we need to make sure we’re using an account with permissions to reboot the computer in question.

You can use the runas CMD command to launch a PowerShell with the necessary credential.

PS C:\>runas /env /user:administrator@domain.local “powershell.exe”

Then you will be able to link the other computer to your variable, and fire off the simple reboot method. 

PS C:\>$your_server = gwmi win32_operatingsystem -computer yourservername

Click to continue reading "Reboot a computer remotely with WMI and PowerShell"

Written by daniel.nerenberg on May 18th, 2007 with no comments.
Read more articles on PowerShell.

Create an AD user in PowerShell

PowerShell allows you to read, write and update Active Directory Objects. In conjunction with PowerShell’s many other advanced features this provides a great environment to manage your AD, and to automate tasks.

To Create a user object:

First we need to set a variable to hold the domain object, and link the instance to the domain.

PS C:\> $domain = [ADSI] “LDAP://main:389/dc=domain,dc=local”

This will allow you to interact with AD from using this $domain variable.

You can list the root of your domain by typing:

PS C:\> $domain.psbase.Get_children()

This will list the root containers in your active directory by Distinguished Name.

 

To get more information about a specific branch in the directory we can associate that branch to a new variable.

$usersOU = [ADSI] “LDAP://CN=Users,DC=domain,DC=local”

and then again using the “psbase.Get_children()”

$usersOU.psbase.Get_children()

This will list all the AD objects (users and computers) in the OU.

Lets finish off by creating a user.

PS C:\> $newUser = $usersOU.Create(”user”,”cn=MyNewUser”)
PS C:\> $newUser.put(”title”, “PowerShell Test Account”)
PS C:\> $newUser.put(”employeeID”, 123)
PS C:\> $newUser.put(”description”, “Test User Account for LazyAdmin Demo”)
PS C:\> $newUser.SetInfo()

Now If you enter this into your command prompt you may get an access denied error:

This is

Click to continue reading "Create an AD user in PowerShell"

Written by daniel.nerenberg on May 14th, 2007 with no comments.
Read more articles on PowerShell.

PowerShell DIY commands (using functions)

As you might have guessed I’m a lazy admin :) Now being a lazy admin doesn’t mean I sit around pondering whether captain Kirk is better than Captain Picard, and all the while, hope somebody is taking care of what I’m supposed to be doing. It means I work smarter not harder. Yes I know 2 clichés in the same paragraph. And everyone knows Picard is totally the best Captain.

So the point of all this is PowerShell has this awesome feature for creating functions. What is a function? Well for those who don’t have a programming/developers background, a function is a chunk of code that performs an easily reusable set of instructions.

To draw an analogy, a car has many parts. Each part performs a specific function. If we were to lump every function of every part of a car into one giant part it would be much harder to design. It would also be harder to fix, and much more expensive to replace.

When programmers code applications they use the same idea. If they write up some code that does one thing very well. For instance format a string of text; they will often put this generic code

Click to continue reading "PowerShell DIY commands (using functions)"

Written by daniel.nerenberg on May 9th, 2007 with no comments.
Read more articles on PowerShell.

No older articles

Newer articles »