Showing posts with label powershell. Show all posts
Showing posts with label powershell. Show all posts

Sunday, 16 March 2014

PowerShell: How much physical memory

Get-WMIObject -class win32_physicalmemory | Format-Table devicelocator, capacity –a

This PowerShell command will return the amount of memory in each slot.

MSDN: Win32_PhysicalMemory class

PowerShell domain join and computer rename

Add-Computer -DomainName Domain01 –Restart

TechNet: PowerShell Add-Computer

Rename-Computer -NewName Server044 -DomainCredential Domain01\Admin01 –Restart

TechNet: PowerShell Rename-Computer

Sunday, 9 March 2014

PowerShell shutdown all running Hyper-V VMs

PowerShell Script that shuts down all running virtual machines on named Hyper-V server. It shuts them down one at a time waiting while a VM shuts down before shutting down the next. Remember to substitute your <servername>. Quick way to shutdown the test environment at the end of the day.

$runningVM=Get-VM –ComputerName <servername> | Where-Object {$_.State -eq 'Running'}

foreach($cn in $runningVM){
Write-Host "Shutting down $($cn.name)"
stop-vm $cn.name -force
}

Add the following lines to shut down the Hyper-v server

Write-Host "Shutting down Hyper-V server”

Stop-Computer –computername <servername> –force

Start Virtual Machine when you start Hyper-V

I have a Virtual Machine that I want to start automatically when I start the Hyper-V server in my test environment. How would I do/undo this with PowerShell.

Start a VM called vm01 automatically

SET-VM –name vm01 –AutomaticStartAction Start

Prevent a VM called vm01 from starting automatically

SET-VM –name Vm01 –AutomaticStartAction Nothing

Wild cards a permissible – every VM that start with b

SET-VM –name b* –AutomaticStartAction Start

Saturday, 8 March 2014

PS Script will not run from current directory

Your PowerShell script will not run from the current folder.

If you have myscript.ps1 in c:\myfolder and your current directory is c:\myfolder you will find your script will not run.  PowerShell does not search the current folder only those included in the Path variable.

Include the full path c:\myfolder\myscript.ps1 or .\myscript.ps1

the other alternative is to add you folder to the path variable.

Auto load PowerShell Window in Server Core

When working with a server core I like to have a PowerShell window open. Here is a quick way to do it.

You could just type PowerShell in the cmd window to turn it into a PowerShell window or type Start PowerShell to open a separate PowerShell window.

To have it there waiting for you:

  1. From cmd prompt run Regedit
  2. Navigate to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
  3. Add string Value called PowerShell with value cmd.exe /k %windir%\system32\WindowsPowerShell\v1.0\powershell.exe.

Alternatively use the PowerShell Command

New-ItemProperty -path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\run -Name PowerShell -Value C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Type string

Monday, 3 March 2014

Add a static IP route

TechNet: Add a static IP route

route adddestinationmasksubnetmaskgatewaymetriccostmetricifinterface

example #1: route add 10.0.0.0 mask 255.0.0.0  192.168.1.1

by adding this to a workstation you are saying they the route to the 10.0.0.0 network is via gateway 192.168.1.1. This assumes the workstation is on network 192.168.1.0.

This command would result in a temporary route to make it persistent add –p to the command.

example #2: route add 10.0.0.0 mask 255.0.0.0  192.168.1.1 –p

Powershell 4.0:

New-NetRoute

Get-NetRoute | Format-List -Property *

Saturday, 1 March 2014

Rename folder/directory from command line

Rename folder\directory from command line using powershell

rename-item –path ‘c:\oldfoldername’ –newname ‘newfoldername’

“I was working with Hyper-V 2012 R2 free deployment in workgroup configuration and found that I had to change user to the built-in administrator account rather than a created administrator account to successfully run this command.”

Sunday, 23 June 2013

Tuesday, 18 June 2013

Tuesday, 11 June 2013

PowerShell determine what version is installed

What version of PowerShell is installed on a machine

Open PowerShell and type Get-Host

Windows 7 – version 2.0

image

Windows 8 – version 3.0

image

http://technet.microsoft.com/en-us/library/bb978526.aspx

Wednesday, 31 October 2012

Free idera PowerShell Plus 4.6

PowerShell Plus 4.6 the latest release of idera’s integrated development environment (IDE) is available as a free download from their website.

Download: PowerShell Plus 4.6

Wednesday, 24 October 2012

PowerShell on Windows 2008 Server Core

Windows Server 2008 R2 has native support for PowerShell. To install on Windows 2008 server core R1?

PowerShell on Server Core

This is a third party blog entry that I have not checked or whether PowerShell on Windows 2008 R1 Core was resolved with later patch.

Follow up:

I cannot test this as my core is R2

http://technet.microsoft.com/en-us/magazine/ff476070.aspx

Wednesday, 9 December 2009

Exchange 2007 Manage Send as Permission

Important:  If Wendy Smith needs to send as Bob Brown the permission is set on Bob Brown’s mailbox.

Possible Gotcha: Notice that in the shell command Bob Brown uses the display name and Wendy.Smith uses the logon name

Add send as permission using EMC

Open EMC Under Recipient Configuration and then Mailbox right click on the required mailbox and select Manage Send as Permission

Click Add then select user then OK, Manage and Finish.

You will notice the Security Principal NT AUTHORITY\SELF this is so the user can send from their own mailbox.

Exchange Management Shell command for SBS 2008:
Add-ADPermission -Identity 'CN=Bob Brown,OU=SBSUsers,OU=Users,OU=MyBusiness,DC=sec,DC=local' -User 'SEC\Wendy.Smith’-ExtendedRights 'Send-as'

 

Remove send as permission using EMC

Caution: If you are deleting users do not delete the Security Principal NT AUTHORITY\SELF.

Open EMC Under Recipient Configuration and then Mailbox right click on the required mailbox and select Manage Send as Permission

Click The red Cross to delete a user then Manage and Finish.

Exchange Management Shell command for SBS 2008:
Remove-ADPermission -Identity 'CN=Bob Brown,OU=SBSUsers,OU=Users,OU=MyBusiness,DC=sec,DC=local' -User 'SEC\Wendy.Smith' -InheritanceType 'All' -ExtendedRights 'send-as' -ChildObjectTypes $null -InheritedObjectType $null -Properties $null