Script in remote server
hi .. im using machine run script validate if specific folder exist in remote win 2008 r2 server , if doesnt exist, shall create it.below script.
how can make below lines in script applied on a remote server?
if ( !(test-path $folder_name) )
{new-item -type directory -path $folder_name |out-null} else {write-host "$folder_name exists" -foregroundcolor yellow }
ammarhasayen
hi .. im using machine run script validate if specific folder exist in remote win 2008 r2 server , if doesnt exist, shall create it.below script.
how can make below lines in script applied on a remote server?
if ( !(test-path $folder_name) )
{new-item -type directory -path $folder_name |out-null} else {write-host "$folder_name exists" -foregroundcolor yellow }
ammarhasayen
if have psremoting enable, can use invoke-command:
$scriptblock ={ param($folder_name) if ( !(test-path $folder_name) ){ new-item -type directory -path $folder_name |out-null } else { write-host "$folder_name already exists" -foregroundcolor yellow } } invoke-command -computer $server -script $scriptblock -argument $folder_name
Windows Server > Windows PowerShell
Comments
Post a Comment