Monday, 22 September 2014

PowerShell: IntPtr


A platform-specific type that is used to represent a pointer or a handle.



1) It's a "native (platform-specific) size integer." It's internally represented as void* but exposed as an integer. You can use it whenever you need to store an unmanaged pointer and don't want to use unsafe code. IntPtr.Zero is effectively NULL (a null pointer).

2) IntPtr is just a simple integer-based struct that can hold a pointer (ie., 32 bit size on 32-bit systems, 64-bit size on 64-bit systems).


Note:
http://msdn.microsoft.com/en-us/library/System(v=vs.110).aspx

http://msdn.microsoft.com/en-us/library/system.intptr(v=vs.110).aspx



Powershell UI : PSHostUserInterface.PromptForCredential Method


PSHostUserInterface.PromptForCredential Method

prompts the user for credentials for a specified target. The variants of this method can be used to prompt the user with a specified prompt window caption, prompt message, user and target name, credential types allowed to be returned, and user interface (UI) behavior options.



Parameters

caption
The caption for the message window.
message
The text of the message.
userName
The user name whose credential is to be prompted for. If this parameter set to null or an empty string, the function prompts for the user name first.
targetName
The name of the target for which the credential is collected.
************************************************************************************************

PSHostUserInterface.PromptForCredential Method (String, String, String, String, PSCredentialTypes, PSCredentialUIOptions)

Parameters

caption
The caption for the message window.
message
The text of the message.
userName
The user name whose credential is to be prompted for. If this parameter set to null or an empty string, the function will prompt for the user name first.
targetName
The name of the target for which the credential is collected.
allowedCredentialTypes
A bitwise combination of the PSCredentialTypes enumeration values that identify the types of credentials that can be returned.
options
A bitwise combination of the PSCredentialUIOptions enumeration values that identify the UI behavior when it gathers the credentials.
************************************************************************************************






Friday, 19 September 2014

Powershell: $host.ui.PromptForChoic


$host.ui.PromptForChoic

PromptForChoice method (which belongs to the UI property of the $host object). When we call PromptForChoice we need to pass four parameters, in order:
  • $title, the title of our menu.
  • $message, the message displayed to the user.
  • $options, the menu options.





$title = "Delete Files"
$message = "Do you want to delete the remaining files in the folder?"

$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
    "Deletes all the files in the folder."

$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
    "Retains all the files in the folder."

$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)

$result = $host.ui.PromptForChoice($title, $message, $options, 0)

switch ($result)
    {
        0 {"You selected Yes."}
        1 {"You selected No."}
    }


----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------

$t = "Location"
$msg = "What location?"
$CFT = New-Object System.Management.Automation.Host.ChoiceDescription "&A choice 1", "1"
$CON = New-Object System.Management.Automation.Host.ChoiceDescription "&B choice 2", "2"
$ELP = New-Object System.Management.Automation.Host.ChoiceDescription "&C choice 3", "3"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($CFT, $CON, $ELP)
$result = $host.ui.PromptForChoice($t, $msg, $options, 1)


----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------

Powershell script object model : LoadWithPartialName


LoadWithPartialName
Loads an assembly from the application directory or from the global assembly cache using a partial name.

LoadWithPartialName
Loads an assembly from the application directory or from the global assembly cache using a partial name. The assembly is loaded into the domain of the caller using the supplied evidence.



Powershell script:
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$computer = [Microsoft.VisualBasic.Interaction]::InputBox("Enter a computer name", "Computer", "$env:computername")

write-output $computer

----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------



This method first calls Load. If the assembly is not found, this method returns the assembly from the global assembly cache that has the same simple name, and the highest version number.

Urls:
http://blogs.msdn.com/b/suzcook/archive/2003/05/30/57159.aspx

Powershell Interaction Class for textbox


The Interaction module contains procedures used to interact with objects, applications, and systems.


[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$computer = [Microsoft.VisualBasic.Interaction]::InputBox("Enter a computer name", "Computer", "$env:computername")

write-output $computer


Friday, 12 September 2014

PowerShell : Cannot be loaded because the execution of scripts i s disabled on this system.


File D:\vish\powershell\Untitled2.ps1 cannot be loaded because the execution of scripts i
s disabled on this system. Please see "get-help about_signing" for more details.
At line:0 char:0




Set-ExecutionPolicy RemoteSigned



Url Helps you more:
http://technet.microsoft.com/en-us/library/ee176961.aspx