1RedOne

PS Profile

Aug 7th, 2014
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.01 KB | None | 0 0
  1. function Search-Google
  2. <#
  3. .Synopsis
  4. Searches the Googes
  5. .DESCRIPTION
  6. Lets you quickly start a search from within Powershell
  7. .EXAMPLE
  8. Search-Google Error code 5
  9. --New google search results will open listing top entries for 'error code 5'
  10.  
  11. .EXAMPLE
  12. search-google (gwmi win32_baseboard).Product maximum ram
  13.  
  14. If you need to get the maximum ram for your motherboard, you can even use this
  15. type of syntax
  16. #>
  17. {
  18.  
  19.  
  20. Begin
  21. {
  22. $query='https://www.google.com/search?q='
  23. }
  24. Process
  25. {
  26. Write-Host $args.Count, "Arguments detected"
  27. "Parsing out Arguments: $args"
  28. for ($i=0;$i -le $args.Count;$i++){
  29. $args | % {"Arg $i `t $_ `t Length `t" + $_.Length, " characters";$i++} }
  30.  
  31.  
  32. $args | % {$query = $query + "$_+"}
  33. $url = "$query"
  34. }
  35. End
  36. {
  37. $url.Substring(0,$url.Length-1)
  38. "Final Search will be $url"
  39. "Invoking..."
  40. start "$url"
  41. }
  42. }
  43.  
  44. Function Uptime{
  45. param([parameter(Mandatory=$false)][string]$computer=".")
  46. #$computer = read-host "Please type in computer name you would like to check uptime on"
  47.  
  48. $lastboottime = (Get-WmiObject -Class Win32_OperatingSystem -computername $computer).LastBootUpTime
  49.  
  50. $sysuptime = (Get-Date) – [System.Management.ManagementDateTimeconverter]::ToDateTime($lastboottime)
  51.  
  52. Write-Host "$computer has been up for: " $sysuptime.days "days" $sysuptime.hours "hours" $sysuptime.minutes "minutes" $sysuptime.seconds "seconds"}
  53.  
  54. Function diskusage
  55. {
  56. param([parameter(Mandatory=$false)][string]$remotepc=".")
  57. #$remotepc = Read-host 'For which computer?'
  58. Get-WmiObject win32_logicaldisk -ComputerName $remotepc -Filter "drivetype=3" | select SystemName,DeviceID,VolumeName,@{Name="Size(GB)";Expression={"0:N1}" -f($_.size/1gb)}},@{Name="FreeSpace(GB)";Expression={"{0:N1}" -f($_.freespace/1gb)}}}
  59.  
  60. Function patches{
  61. param([parameter(Mandatory=$false)][string]$remotepc=".")
  62. #$remotepc = Read-host 'For which box?'
  63. Get-WmiObject -Class "win32_quickfixengineering" -ComputerName $remotepc | select hotfixid,installedon}
  64.  
  65.  
  66.  
  67.  
  68. function RemindMe-Comparators {
  69.  
  70. $writeout = @"
  71. Windows PowerShell includes the following comparison operators:
  72.  
  73. -eq
  74. -ne
  75. -gt
  76. -ge
  77. -lt
  78. -le
  79. -Like
  80. -NotLike
  81. -Match
  82. -NotMatch
  83. -Contains
  84. -NotContains
  85. -In
  86. -NotIn
  87. -Replace
  88. "@
  89.  
  90. "$writeout"
  91.  
  92. }
  93.  
  94. function RemindMe-Git{
  95. $giturl = "https://github.com/feelingsofwhite/MaximumPower"
  96.  
  97.  
  98. $nav = Read-host "Navigate to Azure?"
  99. if ($nav -eq 'Y')
  100. {$ie.visible = $true}
  101. #"Chxda7izL3GR" | clip
  102. }
  103.  
  104. $custom = @"
  105. --Custom Commands Available--
  106. RemindMe-Azure`t`tDisplay Reminder information for Azure
  107. RemindMe-Comparators`tDisplay Reminder information on Comparison Operators
  108. RemindMe-Git`t`tDisplay Remind information on how to use Git
  109. Search-Google`t`tQuickly Launch a google Search
  110. Play-Bubbles`t`tPop `dem Bubbles!
  111. Get-SwitchStatus`t`tSee the status of users
  112. Uptime`t`tEasy Uptime
  113. DiskUsage`t`tGets Disk Usage
  114. Patches`t`tLists Patches
  115. "@
  116.  
  117. Write-Host -fore Yellow -Back Black $custom
  118.  
  119. #Write-Host -fore Yellow -Back Black "Searching for Azure and Azure Platform Modules..."
  120.  
  121. if (Test-path "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\"){
  122. Write-Host "Azure Modules found, importing"
  123. gci 'C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure' *.psd1 | select -ExpandProperty Fullname| Import-module -PassThru
  124. }
  125. ELSE
  126. {#Write-Warning "Azure and Azure Platform Modules not detected, skipping..."
  127. }
  128.  
  129.  
  130.  
  131. if (Test-path "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1"){
  132. import-Module "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1" -PassThru
  133. }
  134. ELSE
  135. {#Write-Warning "Config Manager PowerShell module not detected, skipping..."
  136. }
  137.  
  138.  
  139. if (test-path C:\Users\sowen\dropbox\docs\iVision\Recall\Scripts){"Recall Scripts Directory detected, must be iVision laptop, navigating...";Set-location "C:\Users\sowen\dropbox\docs\iVision\Recall\Scripts"}
  140.  
  141. function Play-Bubble{
  142. [CmdletBinding()]
  143. Param(
  144. [Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
  145. $bubbles="0"
  146. )
  147.  
  148. $sound = new-Object System.Media.SoundPlayer;
  149. $sound.SoundLocation = "C:\users\sowen\Downloads\bubble_Pop-Sound_Explorer-1206462561.wav"
  150.  
  151. 1..[int]$bubbles | % {$sound.Play();start-sleep -Milliseconds 150}
  152. }
  153.  
  154. ####################################################################
  155. # ----Name : iVision Recall Quest Switch Status
  156. # ---Author: Stephen Owen, iVision, 7.24.2014
  157. # Function : Use this tool to determine if a user account has switched or not, based on the account's Source targetAddress property
  158. # ---Usage : Get-SwitchedStatus <$username>
  159.  
  160.  
  161. Function Get-SwitchedStatus {
  162. <#
  163. .Synopsis
  164. Use this tool to determine if a user account has switched or not, based on the account's Source targetAddress property
  165. .DESCRIPTION
  166. This tool connects to the Source (legacy) AD Domain and looks up the specified user object, returning the .targetAddress property
  167. connects to the target domain to move the user account to the correct OU
  168. .PARAMETER UserName
  169. <Mandatory> Specify the username to inquire
  170. .EXAMPLE
  171. Get-SwitchedStatus -UserName Stephen.Owen
  172. > This tool will connect to the source, and grab the targetAddress property of the object <Stephen.Owen>. If this contains *@source.qmm, the account is most likely unSwitched. If this value contains *@target.qmm, then the account is most likely Switched.
  173. .EXAMPLE
  174. "Stephen.Owen","Mark.Wuerslin" | ForEach-Object {Get-SwitchedStatus -UserName $_}
  175. > Perform Get-SwitchedStatus on both Stephen.Owen, then Mark.Wuerslin
  176. #>
  177. [CmdletBinding()]
  178. param([parameter(Mandatory=$true)][string]$UserName,[string]$service="amatldc01")
  179. #Write-host "Checking for Quest Active Roles PSSnapIn..." -ForegroundColor White -NoNewline
  180. $Host.UI.RawUI.WindowTitle="---Get UserSwitchedStatus Tool"
  181. Write-Progress -Activity ("Checking for Quest Active Roles PSSnapIn...") -PercentComplete 25 -Status "Connecting"
  182. if (-not ((Get-PSSnapin).Name -contains "Quest.ActiveRoles.ADManagement")){
  183.  
  184. try {Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction Stop}
  185. catch{
  186. #Write-host "[ERROR]" -ForegroundColor Red
  187. Write-Warning "This tool depends on the Quest Active Roles tools to operate"
  188. $DL = Read-Host "Download? Y/N"
  189. IF ($DL -eq "Y"){
  190. Start 'http://www.quest.com/quest_download_assets/individual_components/Quest_ActiveRolesManagementShellforActiveDirectoryx86_151.msi'
  191. "Exiting..."
  192. }
  193. ELSE{"Exiting...";break}
  194.  
  195. BREAK
  196. }
  197. finally{#Write-Host "[OKAY]" -ForegroundColor Green
  198. }
  199. }
  200. ELSE{start-sleep -Milliseconds 150
  201. #Write-Host "[OKAY]" -ForegroundColor Green
  202. Write-Progress -Activity ("Checking for Quest Active Roles PSSnapIn...") -PercentComplete 50
  203. }
  204. if (-not($credential)){
  205. $credential= Get-Credential -Message "Enter credentials which can browse AD in Source and Target"}ELSE{"Cached credential detected, continuing..."
  206. }
  207.  
  208. #Connect to source
  209. start-sleep -Milliseconds 150
  210. #Write-Host "Connecting to Source..." -NoNewline
  211. Write-Progress -Activity ("Connecting to source...") -PercentComplete 50 -Status "Connecting..."
  212. try {Connect-QADService $service -Credential $credential -ErrorAction Stop}
  213. Catch{
  214. Write-warning "Error ocurred connecting to AMATLDC01 to pull source OU paths, check credentials..."
  215. BREAK
  216. }
  217. finally{#Write-Host "[OKAY]" -ForegroundColor Green
  218. }
  219.  
  220. Try {start-sleep -Milliseconds 150
  221. Write-Progress -Activity ("Looking up $username on " + (Connect-QADService).DefaultNamingContext.DnsName) -PercentComplete 75 -Status "Gathering Info..."
  222. $user = get-qaduser $username -DontUseDefaultIncludedProperties -IncludedProperties targetAddress -Service $service -ConnectionAccount $credential.UserName -ConnectionPassword $credential.Password -ErrorAction Stop
  223. Write-Debug "Troubleshoot `$user"}
  224.  
  225. catch {Write-Warning ("Unable to perform Get-QADUser for object $username from service: " + (Connect-QADService).DefaultNamingContext.DnsName + "`n check UserName")
  226. }
  227. Write-Debug "Troubleshoot `$user"
  228.  
  229. if ($user){
  230. if (-not($user.targetAddress)){
  231. Write-Warning ("Unable to find targetAddress: $userName has NOT Switched")
  232. BREAK
  233. }
  234. }
  235.  
  236. if ($user.targetAddress -like "*@target.qmm"){"$userName Has Switched"}
  237. ELSE{"$user HAS NOT Switched"}
  238.  
  239. }
Add Comment
Please, Sign In to add comment