IF OR ELSE Statements
I am trying to get the following to work based on the machine (computer name):
If the computer name = desktop1 or desktop2 or desktop3 then
do nothing
else
xcopy "\\domain.localt\db\template" "c:\y" /y /d /I /c /e
Im not a scripting type of person by I want to learn
February 19th, 2015 12:59pm
Hi,
I would suggest creating a txt file with a list of all your computers (put it in C:\temp or somewhere) and use this this help you
$PCLIST = Get-Content C:\Temp\PCLIST.txt
Foreach ($PC in $PClist) {
if ($PC -eq "PC1"-or $PC -eq "PC2"-or $PC -eq "PC3"){
#exclude PC
Write-Host "Skip $PC"
}
else {
#Include PC
xcopy "\\domain.localt\db\template" "c:\y" /y /d /I /c /e
}
}
YOu will need to replace PC1 PC2 and PC3 with the names you want to skip.
Let me know if you have any trouble.
Joe
-
Marked as answer by
JakeBuzzMan
Thursday, February 19, 2015 8:44 PM
February 19th, 2015 2:18pm
Also I'm not sure what your "xcopy "\\domain.localt\db\template"
"c:\y" /y /d
/I /c /e" is doing. you might want to stick the PC name in if you're trying to pull something from it
February 19th, 2015 2:21pm
\\domain.local\... is a what a DFS share looks like.
if($pc1 -notin 'desktop1','desktop2','desctop3'){
xcopy "\\domain.localt\db\template" "c:\y" /y /d /I /c /e
}
February 19th, 2015 4:33pm
First prize to you, its absolutely a DFS share. Thanks for all your input.
jrv where is the string that is stored in the variable $pc1 ?
-
Edited by
JakeBuzzMan
Thursday, February 19, 2015 8:49 PM
February 19th, 2015 11:46pm
From inside a batch script :
@echo off
for %%a in (desktop1 desktop2 desktop3) do if /i "%%a"=="%computername%" goto :eof
xcopy "\\domain.localt\db\template" "c:\y" /y /d /I /c /e
February 21st, 2015 6:43am
Sorry about all of you who got it wrong. See you at next year's prom queen contest. Ciao baby!
February 21st, 2015 7:22am
Totally agree, a batch file is the right solution in this case.
February 21st, 2015 2:08pm
First prize to you, its absolutely a DFS share. Thanks for all your input.
jrv where is the string that is stored in the variable $pc1 ?
if($env:COMPUTERNAME -notin 'desktop1','desktop2','desctop3'){
xcopy "\\domain.localt\db\template" "c:\y" /y /d /I /c /e
}
February 21st, 2015 2:13pm