Powershell

Powershell Script to inventory the mail enabled Public Folders.

export-mail-enabled-public-folders.ps1 ## $resultsarray = @() $mailpub = Get-MailPublicFolder -ResultSize unlimited foreach ($folder in $mailpub) { $email = $folder.primarysmtpaddress.local + "@" + $folder.primarysmtpaddress.domain $pubfolder = Get-PublicFolder -Identity $folder.identity $folderpath = $pubfolder.parentpath + "\" + $pubfolder.name # Create a new object for the purpose of exporting as a CSV $pubObject = new-object PSObject $pubObject...

Securely Storing Encrypted Password to use later in Script.

Remember! When you are creating the Encrypted-Password.txt DO THIS running under the user credentials that will run the script or task eventually. If you do not do this it will not work! For example if you create the file under account A and rund the task under Account B it will not work! The secure string is also linked to the account that created/exported it. From a Powershell CMD do: $credential = Get-Credential You will be prompted to fill in your credentials to save After this we will ge...

Mass/Bulk Changing User UPNs to the same as the user Email address

the only thing you should change is the $ou variable to represent the Searchbase. In this example the searchbase goes 1 OU deep but you can change that ofcourse by setting another LDAP. $ou = "<OU=Name of OU>,DC=<domainname>,DC=<extention>" $users = (get-aduser -searchbase $ou -filter * | select -ExpandProperty Samaccountname) foreach ($user in $users) { Set-ADUser $user -UserPrincipalName (Get-ADUser $user -Properties mail | Select-Object -ExpandProperty mail) }

PowerShell Predefined Variables

PowerShell Predefined Variables By Xah Lee. Date: 2009-07-30, 2012-03-31 PowerShell has several predefined variables, called automatic variables. Some of them are used for scripting, some give info about the environment. For example, $_ is a variable that contains the current argument (similar to Perl's “$_”), and is a most frequently used variable in scripting. The $Host is a variable that contains info about current PowerShell environment. This page gives explanation and sample use, of the m...

How to get All Alliases of a certain Command

How to get all alliases that can be used In this example get-childitem # get all aliases of get-childitem get-alias | where-object {$_.Definition -eq "get-childitem"}

Cleanup User Download Folders in Profile Directories

run this powershell script on the file server which houses the Profile Directories. $ROOTDIR = "<Relative path to Profiles DIR>" $item = ( gci $ROOTDIR) foreach ( $USERDIR in $it em ) { gci "$ROOTDIR\$USER DIR\downloads" -file -recurse | remove-item } First we need to create and ARRAY (=variable with multiple items, this we do by filling $item which the content of gci (get-chil ditem) = all of the directories under D:\Profiles) What this script does is.. for EACH Directory i...

PowerCLI : Remove Media (ISO) from VM's

Use this command and fil the list.txt with the exact names of the VM's _Format_ VM1 VM2 etc.. Get-CDDrive -VM (Get-Content C:\scripts\list.txt) | Set-CDDrive -nomedia Or use this command to remove the media of ALL VM's Get-CDDrive -VM * | Set-CDDrive -nomedia

Changing Certain Values to Other Values before PIPING them to a command.

Changing Certain Values to Other Values before PIPING them to a command. For Example you have a .csv file with values like Job Title and Name that you want to convert to other values, you can use this syntax. _the n= is a short version of Name= and the e= is a short version of expression=_ @{n='title';e={$_.'Job Title'}},@{n='samaccountname';e={$_.name}} So the normal command would be like import-csv users.csv | select Name,Department,City,'Job Title',Name | new-aduser which will NOT w...

How to schedule a .ps1 PowerCLI script

Create a .cmd file with something like this in it: C: CD "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI" powershell.exe -psc vim.psc1 " & "C:\scripts\<name of script>.ps1"

Vmotion list of VM's from one host to another

Use this command in PowerCLI Connect-VIServer -Server <IP of DNS name of Vcenter> -user <NETBIOSDomain\username> -password <password> Get-VM -Name ( Get-Content C:\Temp\List.txt ) | Move-VM -Destination <dns.server.name> The list.txt should contain a list of VM.NameA VM.NameB etc... Your may work with Wildcards if the Names are long VM.lala* VM.baba* Etc..

Vmware PowerCLI - Update Vmware Tools

Connect-VIServer -Server <IP of DNS name of Vcenter> -user <NETBIOSDomain\username> -password <password> $VMs = Get-VM foreach ($vm in $VMs) { $ToolsStatus = $vm.ExtensionData.Guest.ToolsStatus if ($ToolsStatus -ne "toolsOK") { Write-Host "Updating the tools of" $VM.Name $vm | Update-Tools -NoReboot } }