Pages

Showing posts with label Script/Tool. Show all posts
Showing posts with label Script/Tool. Show all posts

Sunday, July 3, 2016

Uninstall an application from PowerShell–Example Windows Live Essential

I was trying to see an option to uninstall and application from the PowerShell after couple of try I got through.

1. Run PowerShell as administrator

2. Get the status of installation, in this example we are trying to check status of Windows Live Essentials installation so enter as,

“Get-WmiObject -Class win32_product | where { $_.Name -like "*Windows Live Essentials*"}”

clip_image001

3. Store the current installation status to a variable, this example ‘$Software’ is the variable
“$software = Get-WmiObject -Class win32_product | where { $_.Name -like "*Windows Live Essentials*"}”

clip_image002

4. Run “$software.Uninstall()” to un install

clip_image004

5. Execute the step 2 to see the status again

Friday, July 1, 2016

Error while running a PowerShell script with 'curl'

This week I was working on a script to back-up a Audiocodes gateway, while running the script I got below error and it took a day of mine to troubleshooting the issue.

Invoke-WebRequest : Cannot bind parameter 'WebSession'. Cannot convert the "%{http_code}" value of type "System.String" to type "Microsoft.PowerShell.Commands.WebRequestSession".At C:\scripts\Untitled4.ps1:20 char:50+ $statuscode = curl -o null.txt $loginurl -w '%{http_code}'+ ~~~~~~~~~~~~~~+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

clip_image001

Solution which worked for me

After digging lot into the issue came to know that the issue was due to an Alias of ‘curl’

To solve the issue run "Remove-Item alias:curl" from the same PowerShell window or write curl.exe instead of writing just 'curl'

Hope this will help you Winking smile

Sunday, June 26, 2016

Enable Hyper-v feature from PowerShell

As you may probably know Hyper-v comes with Windows 10 as Windows feature and if you would like to enable the same from PowerShell then its possible. You can also enable the feature from graphical way but here I am going to mention how its possible by using PowerShell.

1. Run PowerShell as administrator

2. Type “Get-WindowsOptionalFeature -Online |where featureName -Like "*hyper*" |ft” and hit enter. It will show the current status

image
3. Type “enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -All –Verbose” and hit enter. Enter “Y” when prompted
image

4. Enter “Get-WindowsOptionalFeature -Online |where featureName -Like "*hyper*" |ft” gain to see the status, it should show all enabled
image

Enjoy the Hyper-v feature Smile

Tuesday, July 9, 2013

How to implement reporting for a Lync account

I had a strange requirement from one of my client. He wanted to see Lync conferencing policy change on an account!
If the policy is changed then he would like to have mail send to him with the information and the check should happen every one hour. Checking every one hour and reporting it when ever policy change was a nightmare for my Operations team and i thought of automating it by using a powershell script :)
First you have to create a file with current information which can be used for comparing the status of policy.

#import the moudule
Import-Module 'C:\Program Files\Common Files\Microsoft Lync Server 2013\Modules\Lync\Lync.psd1'
#Below line will create a file which can be used for comparing. You have to change the sip address with the username which you are going run it. 
Get-CsUser sip:user@domain.com |select-object Identity, ConferencingPolicy |Export-csv D:\Scripts\AccountMonitoring\Default.csv -NoTypeInformation

Now create a news .ps1 file and schedule the same using schedule task. Here is the code, you have to change the user information with your account and domain.

#Import the Lync module
Import-Module 'C:\Program Files\Common Files\Microsoft Lync Server 2013\Modules\Lync\Lync.psd1'
#Get current policy which is assigned to the user to a file
Get-CsUser sip:user@domain.com |select-object Identity, ConferencingPolicy |Export-csv D:\Scripts\AccountMonitoring\Latest.csv -NoTypeInformation
#give the time to create the file
Sleep 60
#Creating the message which should be send in case there is a change.
$action = "Plase note that Conferencing Policy on account 'account@domain.com' has been changed, so request you to verify the configuration."
#Compare the files
compare-object -referenceobject $(get-content D:\Scripts\AccountMonitoring\default.csv) -differenceobject $(get-content D:\Scripts\LMSAccountMonitoring\latest.csv) |Export-Csv -Path D:\Scripts\AccountMonitoring\Output.csv -NoTypeInformation
$output = Get-Content D:\Scripts\AccountMonitoring\Output.csv
if ($output -eq $null)
    {exit 0}
else
    {
    $smtpServer = "smtp.dmain.com"
    $smtpFrom = "SAccountReporting@domain.com"
    $smtpTo = "prajeesh@domain.com"
    $messageSubject = "Change On Account Policy"
    $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
    $message.Subject = $messageSubject
    $message.IsBodyHTML = $true

    $message.Body = $message.Body + $action

    $smtp = New-Object Net.Mail.SmtpClient($smtpServer)
    $smtp.Send($message)
    }

Thursday, December 13, 2012

How to check SRV records by using ‘nslookup’

Even though the nslookup is very familiar to lot people its a so confusing tool to always Smile Yesterday I had spent lot of time to see whether the srv record which i have created for Lync 2010 is correct or not.

Oops! I didn't mention why I wanted to verify from the client side, I did setup lync 2010 for my client but auto-login for the client was not working. When setup the client to use the server name manually it worked. You all know that, when client starts it always search for _sipinternaltls SRV records its configured to auto-login.

Lets come back to the point how we can check SRV records from nslookup, here is the steps.

  1. Open cmd and type nslookup and press enter key
  2. Inside nalookup type ‘set type=all’ and press enter.
    image
  3. Type ‘_sipinternal._tcp.domainname.com’ and press enter
    image
  4. You will be able to see the SRV record details of _sipinternaltls record. The same way can be followed for any other records like _ladp.

Monday, July 30, 2012

SQL Express Edition Backup by SQLCMD fails with error ‘Named Pipes Provider: Could not open’

Issue

Today I came across a situation that SQL backup by using script with SQLCMD fails.
Below is the error I got,

HResult 0x2, Level 16, State 1
Named Pipes Provider: Could not open a connection to SQL Server [2].
Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : Login timeout expired.

Monday, February 27, 2012

How to mount a vhd as a drive

If you want to open a vhd file and the content then there is builtin option available from Windows 7 or Windows 2008r2

  1. Run command prompt as Administrator
  2. From command prompt type ‘Diskpart’ and press Enter
  3. Under diskpart type  select vdisk file="c:\winr2.vhd"
    image
    Note- in this example the vhd file name is winr2.vhd and in your case you have to choose correct file name and path
  4. type ‘attach vdisk’
    image
  5. Open windows explorer and see new drive is added

Thursday, September 1, 2011

Clear Deleted Item folder from Exchange mailbox with out opening.

 

I could find a script to do this job, this script is utilizing OWA and clearing the Deleted Items folder. For executing this script you may need a account which has rights on all mailboxes from where you want to clear deleted items.

strURL = "http://”ExchangeServer'”/exchange/”E-Mail of the user”/deleted items"
Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.Open "DELETE", strURL, False, strUName, strPwd
objXMLHTTP.setRequestHeader "Depth", "infinity,noroot"
objXMLHTTP.Send().

Monday, August 22, 2011

Delete empty directories by using PowerShell script

It was interesting to create a script for finding empty folder under file share and delete with creating a log of directories.

##########################################################################
#Purpose of this script is to find blank folders from particular location
#and report into a text file and delete.
#Version - 1
#Auther - Prajeesh
##########################################################################

$date = ( get-date ).ToString('yyyyMMdd-HHmm')
$items = Get-ChildItem ‘\\Server1\Operations\2006’ -Recurse
foreach($item in $items)
{
      if( $item.PSIsContainer )
      {
            $subitems = Get-ChildItem -Recurse -Path $item.FullName
            if($subitems -eq $null)
            {
               $item.Fullname | Out-File -FilePath C:\Users\Prajeesh\Desktop\"EmtyFolder-$date.txt" -Append
                "Remove item: " + $item.FullName
                  Remove-Item $item.FullName
            }
      }
}

 

Just copy paste above script into a PowerShell Editor and edit locations [where to scan and where to store the log file] save file as ps1 and execute.