Guest User

Untitled

a guest
Jan 13th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.18 KB | None | 0 0
  1. gwmi win32_service –credential domainusername –computer PC#
  2.  
  3. $Username = 'domainusername'
  4. $Password = 'password'
  5.  
  6. $pass = ConvertTo-SecureString -AsPlainText $Password -Force
  7.  
  8. $SecureString = $pass
  9. # Users you password securly
  10. $MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString –computer PC#
  11.  
  12. $MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString
  13. # Sets yous credentials to be used
  14. #$RemoteConn = New-PSSession -ComputerName "PC#" -Credential $MySecureCreds -Authentication default
  15.  
  16. $Username = 'domainusername
  17. $Password = 'password'
  18. $pass = ConvertTo-SecureString -AsPlainText $Password -Force
  19.  
  20. $SecureString = $pass
  21. # Users you password securly
  22. $MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString
  23.  
  24. gwmi win32_service –credential $MySecureCreds –computer PC#
  25.  
  26. Get-Credential [[-UserName] <String>] -Message <String> [<CommonParameters>]
  27.  
  28. Beginning in Windows PowerShell 3.0, you can use the Message parameter to specify a customized message on the
  29. dialog box that prompts the user for their name and password.
  30.  
  31. The Get-Credential cmdlet prompts the user for a password or a user name and password. By default, an
  32. authentication dialog box appears to prompt the user. However, in some host programs, such as the Windows
  33. PowerShell console, you can prompt the user at the command line by changing a registry entry. For more information
  34. about this registry entry, see the notes and examples.
  35.  
  36. When you submit the command, you are prompted for a password.
  37.  
  38. Starting in Windows PowerShell 3.0, if you enter a user name without a domain, Get-Credential no longer
  39. inserts a backslash before the name.
  40.  
  41. If you omit this parameter, you are prompted for a user name and a password.
  42.  
  43. Required? true
  44. Position? 1
  45. Default value None
  46. Accept pipeline input? false
  47. Accept wildcard characters? false
  48.  
  49. -Message <String>
  50. Specifies a message that appears in the authentication prompt.
  51.  
  52. This parameter is designed for use in a function or script. You can use the message to explain to the user why
  53. you are requesting credentials and how they will be used.
  54.  
  55. This parameter is introduced in Windows PowerShell 3.0.
  56.  
  57. Required? true
  58. Position? named
  59. Default value
  60. Accept pipeline input? false
  61. Accept wildcard characters? false
  62.  
  63. -UserName <String>
  64. Specifies a user name. The authentication prompt requests a password for the user name. By default, the user
  65. name is blank and the authentication prompt requests both a user name and password.
  66.  
  67. When the authentication prompt appears in a dialog box, the user can edit the specified user name. However,
  68. the user cannot change the user name when the prompt appears at the command line. When using this parameter in
  69. a shared function or script, consider all possible presentations.
  70.  
  71. This parameter is introduced in Windows PowerShell 3.0.
  72.  
  73. Required? false
  74. Position? 1
  75. Default value None (blank)
  76. Accept pipeline input? false
  77. Accept wildcard characters? false
  78.  
  79. <CommonParameters>
  80. This cmdlet supports the common parameters: Verbose, Debug,
  81. ErrorAction, ErrorVariable, WarningAction, WarningVariable,
  82. OutBuffer, PipelineVariable, and OutVariable. For more information, see
  83. about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
  84.  
  85. You cannot pipe input to this cmdlet.
  86.  
  87. Get-Credential returns a credential object.
  88.  
  89. You can use the PSCredential object that Get-Credential creates in cmdlets that request user authentication,
  90. such as those with a Credential parameter.
  91. By default, the authentication prompt appears in a dialog box. To display the authentication prompt at the
  92. command line, add the ConsolePrompting registry entry
  93. (HKLM:SOFTWAREMicrosoftPowerShell1ShellIdsConsolePrompting) and set its value to True. If the
  94. ConsolePrompting registry entry does not exist or if its value is False, the authentication prompt appears in
  95. a dialog box. For instructions, see the examples.
  96.  
  97. The ConsolePrompting registry entry works in the Windows PowerShell console, but it does not work in all host
  98. programs. For example, it has no effect in the Windows PowerShell Integrated Scripting Environment (ISE). For
  99. information about the effect of the ConsolePrompting registry entry, see the help topics for the host program.
  100. The Credential parameter is not supported by all providers that are installed with Windows PowerShell.
  101. Beginning in Windows PowerShell 3.0, it is supported on selected cmdlet, such as the Get-WmiObject and
  102. New-PSDrive cmdlets.
  103.  
  104. -------------------------- EXAMPLE 1 --------------------------
  105.  
  106. PS C:>$c = Get-Credential
  107.  
  108.  
  109. This command gets a credential object and saves it in the $c variable.
  110.  
  111. When you enter the command, a dialog box appears requesting a user name and password. When you enter the requested
  112. information, the cmdlet creates a PSCredential object representing the credentials of the user and saves it in the
  113. $c variable.
  114.  
  115. You can use the object as input to cmdlets that request user authentication, such as those with a Credential
  116. parameter. However, some providers that are installed with Windows PowerShell do not support the Credential
  117. parameter.
  118.  
  119. -------------------------- EXAMPLE 2 --------------------------
  120.  
  121. PS C:>$c = Get-Credential
  122. PS C:>Get-WmiObject Win32_DiskDrive -ComputerName Server01 -Credential $c
  123.  
  124.  
  125. These commands use a credential object that the Get-Credential cmdlet returns to authenticate a user on a remote
  126. computer so they can use Windows Management Instrumentation (WMI) to manage the computer.
  127.  
  128. The first command gets a credential object and saves it in the $c variable. The second command uses the credential
  129. object in a Get-WmiObject command. This command gets information about the disk drives on the Server01 computer.
  130.  
  131. -------------------------- EXAMPLE 3 --------------------------
  132.  
  133. PS C:>Get-WmiObject Win32_BIOS -ComputerName Server01 -Credential (Get-Credential -Credential Domain01User01)
  134.  
  135.  
  136. This command shows how to include a Get-Credential command in a Get-WmiObject command.
  137.  
  138. This command uses the Get-WmiObject cmdlet to get information about the BIOS on the Server01 computer. It uses
  139. the Credential parameter to authenticate the user, Domain01User01, and a Get-Credential command as the value of
  140. the Credential parameter.
  141.  
  142.  
  143.  
  144.  
  145.  
  146. -------------------------- EXAMPLE 4 --------------------------
  147.  
  148. PS C:>$c = Get-Credential -credential User01
  149. PS C:>$c.Username
  150. User01
  151.  
  152.  
  153. This example creates a credential that includes a user name without a domain name. It demonstrates that
  154. Get-Credential inserts a backslash before the user name.
  155.  
  156. The first command gets a credential with the user name User01 and stores it in the $c variable.
  157.  
  158. The second command displays the value of the Username property of the resulting credential object.
  159.  
  160.  
  161.  
  162.  
  163.  
  164. -------------------------- EXAMPLE 5 --------------------------
  165.  
  166. PS C:>$Credential = $host.ui.PromptForCredential("Need credentials", "Please enter your user name and password.",
  167. "", "NetBiosUserName")
  168.  
  169.  
  170. This command uses the PromptForCredential method to prompt the user for their user name and password. The command
  171. saves the resulting credentials in the $Credential variable.
  172.  
  173. The PromptForCredential method is an alternative to using the Get-Credential cmdlet. When you use
  174. PromptForCredential, you can specify the caption, messages, and user name that appear in the message box.
  175.  
  176. -------------------------- EXAMPLE 6 --------------------------
  177.  
  178. PS C:>Set-ItemProperty "HKLM:SOFTWAREMicrosoftPowerShell1ShellIds" -Name ConsolePrompting -Value $true
  179.  
  180.  
  181. This example shows how to modify the registry so that the user is prompted at the command line, instead of by
  182. using a dialog box.
  183.  
  184. The command creates the ConsolePrompting registry entry and sets its value to True. To run this command, start
  185. Windows PowerShell with the "Run as administrator" option.
  186.  
  187. To use a dialog box for prompting, set the value of the ConsolePrompting to false ($false) or use the
  188. Remove-ItemProperty cmdlet to delete it.
  189.  
  190. The ConsolePrompting registry entry works in some host programs, such as the Windows PowerShell console. It might
  191. not work in all host programs.
  192.  
  193. -------------------------- EXAMPLE 7 --------------------------
  194.  
  195. The first command saves the user account name in the $User parameter. The value must have the "DomainUser" or
  196. "ComputerNameUser" format.
  197. PS C:>$User = "Domain01User01"
  198.  
  199. The second command uses the ConvertTo-SecureString cmdlet to create a secure string from a plain text password.
  200. The command uses the AsPlainText parameter to indicate that the string is plain text and the Force parameter to
  201. confirm that you understand the risks of using plain text.
  202. PS C:>$PWord = ConvertTo-SecureString –String "P@sSwOrd" –AsPlainText -Force
  203.  
  204. The third command uses the New-Object cmdlet to create a PSCredential object from the values in the $User and
  205. $PWord variables.
  206. PS C:>$Credential = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $PWord
  207.  
  208.  
  209. This example shows how to create a credential object that is identical to the object that Get-Credential returns
  210. without prompting the user. This method requires a plain text password, which might violate the security standards
  211. in some enterprises.
  212.  
  213. -------------------------- EXAMPLE 8 --------------------------
  214.  
  215. PS C:>Get-Credential -Message "Credential are required for access to the \Server1Scripts file share." -User
  216. Server01PowerUsers
  217. Windows PowerShell Credential Request
  218. Credential are required for access to the \Server1Scripts file share.
  219. Password for user ntdevjuneb:
  220.  
  221.  
  222. This command uses the Message and UserName parameters of the Get-Credential cmdlet. This command format is
  223. designed for shared scripts and functions. In this case, the message tells the user why credentials are needed and
  224. gives them confidence that the request is legitimate.
  225.  
  226. -------------------------- EXAMPLE 9 --------------------------
  227.  
  228. PS C:>Invoke-Command -ComputerName Server01 {Get-Credential Domain01User02}
  229.  
  230. Windows PowerShell Credential Request : Windows PowerShell Credential Request
  231. Warning: This credential is being requested by a script or application on the SERVER01 remote computer. Enter your
  232. credentials only if you
  233. trust the remote computer and the application or script requesting it.
  234.  
  235. Enter your credentials.
  236. Password for user Domain01User02: ***************
  237.  
  238.  
  239.  
  240. PSComputerName : Server01
  241. RunspaceId : 422bdf52-9886-4ada-ab2f-130497c6777f
  242. PSShowComputerName : True
  243. UserName : Domain01User01
  244. Password : System.Security.SecureString
  245.  
  246.  
  247. This command gets a credential from the Server01 remote computer. The command uses the Invoke-Command cmdlet to
  248. run a Get-Credential command on the remote computer. The output shows the remote security message that
  249. Get-Credential includes in the authentication prompt.
  250.  
  251. $pass="FooBoo"|ConvertTo-SecureString -AsPlainText -Force
  252. $Cred = New-Object System.Management.Automation.PsCredential('user@domain',$pass)
  253. gwmi win32_service –credential $cre –computer $computer
Add Comment
Please, Sign In to add comment