Powershell

Powershell scripting

if statement

-eq / -ne
-in
-match
e.g. if ( ‘name’ -in $obj.PropertyNames ) { wite-host ‘yes’ } else { write-host ‘no’

for loop

ForEach ( $obj in $Result ) { $obj.Name }

Copy Files

$LocalPath = "C:\Users\jeff_admin.corp\myexcel.xls"
$RemotePath = "\\172.16.246.5\c$\myexcel.xls"
[System.IO.File]::Copy($LocalPath, $RemotePath, $True)

create desktop for system user (to open files)

$Path = "\\172.16.246.5\c$\Windows\sysWOW64\config\systemprofile\Desktop"
$temp = [system.io.directory]::createDirectory($Path)

Execute workbook and macro

$Workbook = $com.Workbooks.Open("C:\myexcel.xls")
$com.Run("mymacro")

Last updated