Browsing "Scripting"

How can I suspend a VM on VMware workstation via Powershell ?

As there is no API for Powershell in VMware worksation, we need to use the built-in tool called ‘vmrun.exe”

This utility can be used to control virtual machines and allows the following operations: start (power on), stop (power off), reset (reboot), suspend (but allow local work to resume), pause (without interrupting), and unpause (continue)

=====Suspend your VMs======

cd “C:\Program Files (x86)\VMware\VMware Workstation”

$RunningVMs = .\vmrun list | select-object -skip 1

Foreach ($RunningVM in $RunningVMs)
{
“Suspending $RunningVM…”
.\vmrun suspend “$RunningVM”
}

 

====Resume your VMs ====

cd “C:\Program Files (x86)\VMware\VMware Workstation”

$SuspendedVMs = gci -Include *.vmx -Recurse -Path C:\VMs

Foreach ($SuspendedVM in $SuspendedVMs)
{
.\vmrun start “$SuspendedVM”
}

How can I stop Server Manager from loading up at start-up on Windows Server 2012

If you would rather open the server manager manually, then follow these steps to prevent it auto starting:

Go into Server Manager, click on the Manage menu item, then go to Server Manager Properties. Once there, simply tick on Do not start Server Manager automatically at logon. That will prevent it from starting up every time.

Apr 28, 2013 - General, Powershell, Scripting    1 Comment

How can I create / name a folder with today’s date?

This is very handy if you are using scripts to generate daily logs and would like to put them in a folder with the current date. You can, of course, tweak the commands to suit your requirements:

 

for /F “tokens=1-4 delims=/ ” %%A in (‘date /t’) do (
set DateDay=%%A
set DateMonth=%%B
set DateYear=%%C
)

set CurrentDate=%DateDay%-%DateMonth%-%DateYear%

md %CurrentDate%

This will give you a newly created folder with today’s date, in the format of DD-MM-YY

How can I search for all users that have the “Network Policy” set to false using PowerShell ?

If you need to search Active Directory to find users who currently have the “Network Access Permission” set to “Deny Access” on the Dial-in tab of their user account

Dial-in

run this Powershell command:

Get-ADUser -Filter {(mail -like “*”) -and (ObjectClass -eq “user”)} -Properties msNPAllowDialin | Where { $_.msNPAllowDialin -match “False” } | fl Name, msNPAllowDialin

You need to ensure you start Powershell with the AD modules installed.

Jul 25, 2007 - General, Scripting, Vista, Windows XP    2 Comments

How can I pre-cache the Microsoft Office 2007 installation files?

Office 2007 uses the MSOCACHE folder as part of its core installation and functionality process. The folder is typically populated during the Office 2007 installation. However, to avoid network activity during installation, you can accomplish a pre-cache by performing the following steps. (Use caret brackets in place of the square brackets.)

1. From the network installation point, use Notepad to open the config.xml file, which is located in the core product folder (e.g., Pro.WW for Office Professional 2007).
2. Find the [LIS] element, and uncomment the line by deleting the opening [!-- and closing --] tags.
3. Set the [CACHEACTION] attribute to “CacheOnly”. The line in Config.xml should look like

[LIS CACHEACTION="CacheOnly" /]

4. Save the config.xml file.
5. Run setup.exe on users’ computers, specifying the fully qualified path to the modified config.xml. For example,

\[server][share]Office12setup.exe /config
\[server][share]Office12Pro.WWConfig.xml

Where can I download Windows PowerShell?

On November 15, Microsoft released Windows PowerShell 1.0 (formerly codenamed Monad) for Windows XP Service Pack 2 (SP2) and Windows Server 2003, which you can download at here . A Windows Vista Release Candidate 1 (RC1) version is also available, with the final Vista version available by January 31, 2007. The download is less than 2MB but does require that Microsoft .NET Framework 2.0 is installed. Once PowerShell is installed, a new Programs group, Windows PowerShell 1.0, will be created, which has a number of shortcuts to documents and the actual Windows PowerShell application shortcut which points to the %SystemRoot%system32WindowsPowerShellv1.0powershell.exe image.

PowerShell is the future command-line and scripting environment for the management and automation of Windows environments, and many new Microsoft technologies have their management built on the PowerShell environment. For example, Microsoft Exchange Server 2007 relies heavily on the PowerShell environment for many management actions.

The base PowerShell also includes a number of command-line tools called cmdlets that allow access to many system resources such as accessing the registry, Windows Management Instrumentation (WMI), services, processes, event logs, and basically every part of the OS.

Common cmd.exe commands such as Dir and Type all work in the PowerShell, but its real power is via its improved cmdlets. To get started, it’s easiest to type

get-help

which opens an overview of the format of the PowerShell syntax and commands to get started. For example, the get-command command will display a list of all the cmdlets, and the get-command will display detailed information on that cmdlet.

Some handy commands to get started are get-service and get-process, which give information about services and processes, respectively. The figure shows a sample search for all processes that start with o:

In this example, the information is displayed in a table format, but you can easily output it to a list by passing format-list as it’s output, as the figure shows.

To get a list of all possible formats, type

get-help format*

at a command line.

Pages:123»