Thursday, August 25, 2016

Run Remote Powershell sessions


To prep a machine for a remote powershell session
  • Start the Windows Remote Management (WS-Management) Service on the remote machine.
  • psexec \\machinename cmd -i
  • winrm quickconfig
Once these tasks are complete you can run a remote powershell session in Powershell ISE.  Start this from File_New Remote Powershell Tab

The session displays the machine name at the prompt to signify that the commands are directed at the remote machine.

More here
http://www.howtogeek.com/117192/how-to-run-powershell-commands-on-remote-computers/

Sunday, August 21, 2016

Change the file date


Here's a little look at file properties and particularly changing the date.

This lists all the properties you might want to use/set/mess with

get-item "c:\test.txt" | get-member *

This list the time relevent properties

get-item "c:\test.txt" | get-member *time

This changes the CreationTime (remember to use US date format)

get-item "c:\test.txt" | % {$_.CreationTime = '07/28/2016 15:28'}

keywords metadata

Here's an explanation of the % sign usage courtesy of Jeffery Hicks who posted this here


The % symbol is also an alias for ForEach-Object. You would use it in an
expression like this:

cat servers.txt | % { get-wmiobject win32_operatingsystem -computer $_}

And you're right, it is also the modulo operator. In the example you saw,
the expression went through numbers 0 to 15 and formatted them using the -f
operator. The $_ is the current object in the pipeline, ie the numbers 0
through 15.

Hope this explanation helps.

--
Jeffery Hicks MCSE, MCSA, MCT
Microsoft PowerShell MVP

Friday, August 5, 2016

Loops and Call


This is an example of a loop and a call to launch an executable.

This link has examples of other loop types
http://www.winserverhelp.com/2010/04/powershell-tutorial-loops-for-foreach-while-do-while-do-until/2/




# after logon, check for a appv package to be present and then launch it when available.
$IsTextHelpPublishedForMe = $Null

$Count =0
While ($Count -le 10)
    {
       
        $IsTextHelpPublishedForMe = Get-AppvClientPackage -packageid 3227A4B4-269A-4970-84B5-302DC1255E40 | select -expand IsPublishedToUser
                       
        If ($IsTextHelpPublishedForMe -eq "True")
       
            {
            $target = $env:LOCALAPPDATA+"\Microsoft\AppV\Client\Integration\3227A4B4-269A-4970-84B5-302DC1255E40\Root\ReadAndWrite.exe"
            & $target
            exit
            }
       
        Else
            {
            #integer is seconds to wait
            Start-Sleep -s 5
            $Count; $Count +=1
            }
    }

Thursday, August 4, 2016

Real World

This post will be updated with Real World quick powershell uses.....

How many Citrix servers are there?
Get-ADComputer -Filter {name -like "*Citrix*Server*Naming*Convention*Pattern*"} | measure