Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. [System.String[]]$compArray = @()
  2. [System.String]$compName = ""
  3. [System.String]$myArrayLocation = ""
  4.  
  5. function SetMultiComp
  6. {
  7. $multipleCompTest = Read-Host 'Are You Wanting To Perform The Following Operation On Multiple Computers? y/n'
  8. switch($true)
  9. {
  10. ($multipleCompTest -match "y"){MultiCompOp}
  11. ($multipleCompTest -match "n"){SingleCompOp}
  12. default{Clear-Host; Write-Host "Invalid Answer"; SetMultiComp;}
  13. }
  14. }
  15. function MultiCompOp($myArrayLocation)
  16. {
  17. Clear-Host
  18. $testLoc = Read-Host 'Please Give The Location Of Your Computer List'
  19. if((Test-Path $testLoc) -eq $true)
  20. {
  21. Set-Variable -Name "myArrayLocation" -Value "$testLoc" -Visibility Public;
  22. MultiCompPrep ($myArrayLocation);
  23. }
  24. else
  25. {
  26. Clear-Host; Write-Host "File Not Found"; MultiCompOp;
  27. }
  28. }
  29. function MultiCompPrep($compName)
  30. {
  31. foreach($compNameInst in $myArrayLocation)
  32. {
  33. Set-Variable -Name "compName" -Value "$compNameInst" -Visibility Public;
  34. main ($compName);
  35. }
  36. }
  37. function SingleCompOp($compName)
  38. {
  39. Clear-Host
  40. $compNameInst = Read-Host 'What Is The Name Of The Computer You Want To Effect';
  41. Set-Variable -Name "compName" -Value $compNameInst -Visibility Public;
  42. main ($compName);
  43. }
  44.  
  45. function main($compName)
  46. {
  47. $collItem = Get-WmiObject -Class Win32_OperatingSystem -ComputerName "$compName"
  48. Foreach($itemInst in $collItem)
  49. {
  50. $itemInst.Reboot()
  51. }
  52. }
  53. SetMultiComp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement