Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all 15028 articles
Browse latest View live

Windows Powershell Export-CSV column/row value as filename

$
0
0

I'm having a problem with Powershell. I need to Export csv files that contains list of details as names as shown below :

Thanks in advance:)

Export-csv "filesnames.csv"

Filename = SUNTestJan3fri1500AUT.csv, i.e. individual values of "Site+Env+Month+Week+Day+Time+Rebootrights".Please help me out.

Main.CSV

CIEnvWeekdayTimeMonthReboot RightsPolicySite
vm-xxxxxTest3 friday15:00JanuaryAUTONSUN
vm-xxxxx1Test3sunday8:00FebruaryAUTONSUN
vm-yyyyyyProd4saturday6:00MarchNoRebootNSUN


Unzipping folders

$
0
0

Where my unzip is unlike others, I have files under a folder inside a zipped folder.

Using GUI, I can 'Extract All' from a zipped folder, into a folder.  Under this folder will be multiple files.

I need a way to do this with a Powershell script.

adding a prefix to a file name if the prefix is not already there

$
0
0

I have a script that adds a prefix to a file name then moves the file from its source directory to a destination directory. The problem I am encountering is that if the destination directory is unavailable for any reason the file fails to move & so remains in the source directory and then the next time the script runs the prefix gets added again so I sometimes end up with files that look like this:

"Prefix_Prefix_Prefix_Prefix_Prefix_Prefix_1234_20141020_9786_8404.tif"

I need to build in some kind of logic that prevents this from happening so that if the Prefix_ is there it doesn't add it again, but not I'm not sure what the best way to do this is.  Here is the code that adds the prefix.

Get-ChildItem $Source\* -include *.jpg,*.tif,*.pdf -exclude *.log | % {Rename-item $_.Fullname ("Prefix_" + $_.Name)}


# When I wrote this script only God and I knew what I was doing. # Now, only God Knows!

Robocopy users HomeDirectory from server1 to server2

$
0
0
ROBOCOPY /E /R:0 "c:\data\users\jsmith" "\\server2\data\USERS\jsmith"

That is my command to copy them to another server. Is ther away to have like a text file that all users in that text will copy their homedirectory to the new server?

False Power Shell Error

$
0
0

I am having a problem with getting a false error with the script below. The false error is random and I am looking for help to determine why the error is happening. Below is a sample of a false and real error.

False Error

"This file was the last file to process:  at"

What a real\legit error looks like:

"This file was the last file to process: \\jcc.jcc.com\omafiles\SPC-ProductionDatabases\Mailstream\1.66750400 14023 RPT10.pdf at 10/10/2014 09:27:25"

$file=Get-ChildItem -path \\jcc.jccsystems.com\omafiles\SPC-ProductionDatabases\Mailstream\* -Include *.pdf |
    Sort LastWriteTime -desc |
    Select-Object -first 1
    Where-Object{ $_.LastWriteTime -gt ([DateTime]::Now.AddHours(-14)) }

if ($file.LastWriteTime -gt ([DateTime]::Now.AddHours(-14))){
    # file newer than 10
}else{
    # file older than 10
   $mailprops=@{
        SmtpServer='1.2.2.15'
        From='ELECTRONIC_FOLDER@jcc.com'To='list-adf@jcc.com'
        Subject='Please check the Electronic Process'
	}
    $body="This file was the last file to process: $($file.Fullname) at $($file.LastWriteTime)"
    Send-MailMessage @mailprops -Body $body
}

Help to Change a dsquery to Get-ADuser

$
0
0

I have this search that works but I need to change it to a get-aduser command so i can pipe to set-aduser where I canmodify the users smartcard required value. I need to carry over these filters to Get-ADuser to limit the results but I haven’t seem to figured out the syntax.

Any help would be apprexiated, I am fairly new to powershell.

$date2 = "Temp Exclusion $((get-date).AddDays(-30).ToString("yyyyMMdd"))"
$date1 = "Temp Exclusion $((get-date).AddDays(-7).ToString("yyyyMMdd"))"
$today = "Temp Exclusion $(Get-Date -Format 'yyyyMMdd')"

dsquery * -limit 0 -filter "(&(extensionAttribute1=standard)(!userAccountControl:1.2.840.113556.1.4.803:=2)(!userAccountControl:1.2.840.113556.1.4.803:=262144)(!memberof=CN=intern,OU=xxx,DC=abc,DC=def,DC=ghi)(!memberof=CN=$today,OU=xxx,DC=abc,DC=def,DC=ghi)(!memberof=CN=$date2,OU=xxx,DC=abc,DC=def,DC=ghi)(!memberof=CN=$date1,OU=xxx,DC=abc,DC=def,DC=ghi)(!memberof=CN=user list,OU=xxx,DC=abc,DC=def,DC=ghi))" -attr givenName,sn,sAMAccountName >> C:\ps\reports\smartcardusers.txt

Findout antivirus installed on multiple computers

$
0
0

Hi Guys,

I need a script to find out antivirus installed on multiple Windows Servers.  I got one by Aman put below. Is there any other you are aware off that can help me inventory the servers. These servers are in a Citrix environment. Please advise guys. Thanks.

function Get-AntivirusName {

[cmdletBinding()] 
param (
[string]$ComputerName = "$env:computername" ,
$Credential
)


 BEGIN
  {
   # Setting WMI query in a variable
      $wmiQuery = "SELECT * FROM AntiVirusProduct"

  }


 PROCESS
  {
   # doing getting wmi
               
   $AntivirusProduct = Get-WmiObject -Namespace "root\SecurityCenter2" -Query $wmiQuery  @psboundparameters # -ErrorVariable myError -ErrorAction 'SilentlyContinue'     
            Write-host $AntivirusProduct.displayName -ForegroundColor Cyan

  }

 END {

  }
} #end  of the function

 

 

 
Get-AntivirusName


Agroman09

how to delete log file after zipping in batch

$
0
0
    

**

    **please check my code ... and suggest any changes to be made ... i m able to zipp the logs but not able to delete those logs.........
        thanking you...
        this is my code....
        @echo off
        set zip="C:\Program Files\7-Zip\7z.exe"
        rem Findout Month, Year and Date
        FOR /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do set year=%%D
        FOR /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do set month=%%B
        FOR /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do set day=%%C
        rem Solve problem Year start and adding 0 in month
        if %month% EQU 01 (
        set month=12
        set /a year=%year%-1
        ) else (
        set /a month=%month%-1
        )
        if %month% LSS 10 set month=0%month%
        rem Set file names for last month file.
        set lastmonthfiles=server.log.%year%-%month%-
        %zip% -tzip  a -y "%lastmonthfiles%.zip" %lastmonthfiles%*
        if exist %lastmonthfiles%.zip(
        DEL server.log.%year%-%month%-*
        )
        ) else (
            echo file not found
            pause
        )**

**

ADSI query freezes PowerShell script when using "localhost" as computername

$
0
0

Hi,

As part of my learning PowerShell I'm writing some basic functions for querying local users and groups.  I have located the following as a "base" for locating local user accounts on a given computer:

$CompObj = [ADSI]"WinNT://$ComputerName,computer"
$Users = $compobj.psbase.children | Where-Object {$_.psbase.schemaclassname -eq "user"}

What I've found (at least on most of the computers that I have tried) is that the script will freeze if run with "localhost" in the $ComputerName variable (which I often do when testing a script).  The point that it freezes is the "... | Where-Object {$_.psbase.schemaclassname -eq "user"}" component of the script.

I verified this by running the following:

$ComputerName = "localhost"
$CompObj = [ADSI]"WinNT://$ComputerName,computer"
$Users = $compobj.psbase.children

This causes no freeze.

So, the creation of the $Users variable does not cause a script freeze.  However, if I try to display the contents of the $Users variable *after* running the above code, I get a list of all of the local users and groups, before it freezes the script completely.  Here are the last two entries I get when I run it (removed references to my production domain):

"

...
DistinguishedName :
Path              : WinNT://acme.local/localhost/Message Capture Users

distinguishedName :
Path              : WinNT://acme.local/localhost/WinRMRemoteWMIUsers

...

"

PowerShell continues to run at this point, prompting me (in the status bar) to press "Ctrl+Break" if I wish to stop it.  If I do, PowerShell displays "Stopping" in the status bar, and in fact it never finishes stopping (I have to close Powershell, though not forcibly).  I ran this on a colleagues computer and we found that the output also includes Services (remember that we didn't filter it this time with the "Where-Object" cmdlet.

So, we reason that something about the services causes the script to freeze.  I have tried this on the following (not hugely extensively, one of each):

Win 7 SP1 x86: Appears to work

Win 7 SP1 x64: script freezes

Win 2008 R2 x64: script freezes

Win 2012 R2 x64: script freezes.

I'm not sure if the architecture is to blame at all, but I don't want to chase this as it's not a high priority; I'm very curious though to know the cause and how to troubleshoot it.

I did trace the problem to the usage of the word "localhost" in the $ComputerName variable; if I use the actual computer name in place of localhost, the script runs exactly as planned and when I try to display the contents of "$User" it does not freeze before showin the services, and displays the services correctly.

So, I'm trying to identify why this happens - I am thinking that I will have to validate the input into my script to prevent usage of the "localhost" value (or find a clever way to translate that into the hostname itself).

Has anyone experienced this issue before or can help me identify what is causing the behaviour?

Checking a File has been exported - Please Help!

$
0
0

Hey, second time posting on a Forum, but need some help with some PS script.

I am expecting this line to return a 'True' value and display the 'Success' message but it isn't, instead returning the 'Unsuccessfull' message, even though both directories that the Test-Path is looking at contain the required files.

Where am I going wrong?

foreach ($server in $xml.config.server.name) {$TestPath=Test-Path "\\$server\D$\PowerShell\*.*" | ForEach-Object { If ($TestPath -eq $true) { Write-Host "PowerShell Scripts Exported to $server Successfully" -ForegroundColor Green} else { Write-Host "`rUnable to Export PowerShell Scripts to $server" -ForegroundColor Red}}}
Unable to Export PowerShell Scripts to TCPP2B1W01
Unable to Export PowerShell Scripts to TCPP2B1W02


Return a value - Powershell

$
0
0

I have created a powershell script that pulls server names from AD.  I then pass those names to a function to ping the server.  I then set a variable "$state" to either LIVE or OFF.  How do I send the variable $state back to the main script?

 

##############################################################
#  Ping server and set set "State"   #########################
##############################################################
Function NetPing($CName, $state)
{
 $result = 0
 $ping = new-object System.Net.NetworkInformation.Ping
 $result = $ping.send($CName)
 trap{ ; continue }
 if ($result.Status -eq "TimedOut")
 { 
  $state = "off"
  Write-Host -NoNewline "."
 }
 elseif ($result.Status -eq "Success")
 {
  #$DataOutput = $CName + "`t " + $result.Address
  #Add-Content "C:\scripts\Ping.txt" -Value $DataOutput
  $state = "live"
  Write-Host -NoNewline "."
    }
 else
    {
  $state = "off"
  Write-Host -NoNewline "."    
    }
 
 return NetPing.$state
}
##############################################################
#  Get Server List from AD   #################################
##############################################################
$strOperatingSystem = "Windows*Server*" 
$objDomain = [ADSI]"LDAP://ou=Virginia Beach,ou=Admin,dc=anycompany,dc=corp,dc=net"
$ComputerInfoFile = New-Item -type file -force "C:\Scripts\ComputerInfo.txt"
$puidFile = New-Item -type file -force "C:\Scripts\puidInfo.txt" 
 Out-File $ComputerInfoFile -encoding ASCII
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
 
$objSearcher.Filter = ("OperatingSystem=$strOperatingSystem")
 
$colProplist = "name", "description"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
 
$colResults = $objSearcher.FindAll()
 
foreach ($objResult in $colResults)
{
    $objComputer = $objResult.Properties; 
 $CName = $objComputer.name
 $CDesc = $objComputer.description
 Write-host -NoNewline "."
 $ServInfo = $CName + "`t" + $CDesc
    "$ServInfo" | Out-File $ComputerInfoFile -encoding ASCII -append
 NetPing("$CName")
 if($state -eq "live")
 {
  "$CName" + " is up and responding to a ping" | Out-File $puidFile -encoding ASCII -append
 }
 else
 {
  "$CName" + " is NOT responding to a ping" | Out-File $puidFile -encoding ASCII -append
 }
}

Useful Script to manage saved credentials on windows XP

$
0
0

Hello,

I have the following issue,.

In my environment it is the necessity to remove cached credentials from stored user names and passwords in windows XP OS. There is a hassle to do this manually on all XP computers. 

To Automate this process I need a right and useful script to run on all machines to delete the saved credentials.  

CMDKEY.exe is the exact solution for me but it don't work on Windows XP machines.

Can you suggest me any other - more helpful script supported for Windows XP..? 
For example: to delete cached credentials..

Thanks in advance,

In need of a Powershell script to move students from an OU to another OU

$
0
0

Good Day Everyone,

I was tasked to move students from the Students OU to Full Time / Part Time OU. I can possibly get this done in a short time BUT since I am a newbie, I would like to know what would be the best approach for me to get this done. 

Details

1. There are about 1700 students

2. Import Students from an CSV file to be moved [fulltimestudents.csv AND parttimestudents.csv]

3. After importing the students > move them to the fulltime or parttime OU

Any suggestions before I start this and thank you all for your help.

AM



Adrian Mohamed

ROBOCOPY in VBScript with Spaces in Folders

$
0
0

Hi, I have a script that backup files with Robocopy and notified in case of errors.

Unfortunately not work folder with spaces. I've tried everything with CHR(34) but it does not work.

Do you have a tip?

That is my script:

Option Explicit
Const cDefaultRobocopyParameter = "*.* /MIR /R:1 /W:1 /COPYALL /X /TS /FP /NDL /NP /ZB"
Const cErrorMailSmtpServer      = "MAILSERVER"
Const cErrorMailSender          = "Backup Job Failed <admin@domain.com>"
Const cErrorMailRecipient       = "admin@domain.com"


Call CopyAndCheck "\\jira-server\c$\Program Files\JIRA Application Data", "D:\ROBOCOPYBAK\DATA\jira-server\JIRA_Application_Data", "D:\ROBOCOPYBAK\LOG\jira-server_JIRA_Application_Data_" & GetDateTime(now) & ".log", cDefaultRobocopyParameter)
Call CopyAndCheck ("\\jira-server\c$\Program Files\JIRA", "D:\ROBOCOPYBAK\DATA\jira-server\JIRA", "D:\ROBOCOPYBAK\LOG\jira-server_JIRA_" & GetDateTime(now) & ".log", cDefaultRobocopyParameter)

Sub CopyAndCheck (Source, Destination, Logfile, Parameter)

	Dim oWshShell, intReturn
	Set oWshShell = CreateObject("WScript.Shell")
	intReturn = -1
	intReturn = oWshShell.Run ("C:\Windows\System32\robocopy.exe " & Source & " " & Destination & " " & Parameter & " /LOG:""" & Logfile & """", 1, true)
	if intReturn > 8 then
	Call SendErrorMail (Source, Destination, Logfile)
	End if
End Sub

Sub SendErrorMail (MailSource, MailDestination, MailLogfile)
    Dim iMsg, iConf, Flds, strMessageBody
    Const cdoSendUsingPort = 2
    Const cdoAnonymous = 0
    set iMsg = CreateObject("CDO.Message")
    set iConf = CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields
    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = cErrorMailSmtpServer
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = "25"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
        .Update
    End With
	iMsg.Fields.Item("urn:schemas:mailheader:X-MSMail-Priority") = "High" ' For Outlook 2003
	iMsg.Fields.Item("urn:schemas:mailheader:X-Priority") = 2 ' For Outlook 2003 also
	iMsg.Fields.Item("urn:schemas:httpmail:importance") = 2 ' For Outlook Express
	iMsg.Fields.Update
	strMessageBody = ""
	strMessageBody = strMessageBody & "Backup Job Failed (robocopy)! " & vbCrLf & vbCrLf
	strMessageBody = strMessageBody & "Source:" & vbTab & vbTab & MailSource & "" & vbCrLf
	strMessageBody = strMessageBody & "Destination:" & vbTab & MailDestination & "" & vbCrLf
	strMessageBody = strMessageBody & "Logfile:" & vbTab & vbTab & MailLogfile & "" & vbCrLf
    With iMsg
        Set .Configuration = iConf
        .To = cErrorMailRecipient ' DEBUG: "admin@domain.com"
        .From = cErrorMailSender
        .Subject = "Backup Job Failed"
        .TextBody = strMessageBody
        .Send
    End With
    Set iMsg = Nothing
    Set iConf = Nothing
    Set Flds = Nothing
End Sub

Function GetDateTime(thisDate)
		GetDateTime = Year(thisDate)
		GetDateTime = GetDateTime & Right("00" & Month(thisDate),2) & ""
		GetDateTime = GetDateTime & Right("00" & Day(thisDate),2) & "_"
		GetDateTime = GetDateTime & Right("00" & Hour(thisDate),2) & ""
		GetDateTime = GetDateTime & Right("00" & Minute(thisDate),2) & ""
		GetDateTime = GetDateTime & Right("00" & Second(thisDate),2) & ""
End Function






Running as administrator causes an infinite loop

$
0
0

I am trying to run the following script:

# Get the ID and security principal of the current user account
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)

# Get the security principal for the Administrator role
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator

# Check to see if we are currently running "as Administrator"
if ($myWindowsPrincipal.IsInRole($adminRole))
   {
   # We are running "as Administrator" - so change the title and background color to indicate this
   $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
   $Host.UI.RawUI.BackgroundColor = "DarkBlue"
   clear-host
   }
else
   {
   # We are not running "as Administrator" - so relaunch as administrator

   # Create a new process object that starts PowerShell
   $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";

   # Specify the current script path and name as a parameter
   $newProcess.Arguments = $myInvocation.MyCommand.Definition;

   # Indicate that the process should be elevated
   $newProcess.Verb = "runas";

   # Start the new process
   [System.Diagnostics.Process]::Start($newProcess);

   # Exit from the current, unelevated, process
   exit
   }

# Run your code that needs to be elevated here
Write-Host -NoNewLine "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

There seems to be two problems with this script.

1) I get a Windows prompt for credentials that I am not sure where it is coming from. I don't want it as I would rather this script (the eventual one being developed) to be run unattended.

2) It goes into an infinite loop after I enter my credentials. It seems to be stuck generating a new window, closing it, generating a new window . . . . . .

Any help with either of these problems would be greatly appreciated. As I don't see anyone else having these issues I am assuming that I am doing something dumb. If so sorry for the newbie questions.

Thank you.

Kevin




Kevin Burton


Hi all ! Compatibility View List question

$
0
0

For IE, there is a list of sites you can change manually for Compatibility View. I found this list in the registry and it is in binary. My organization wants to blacklist a site from this list (in other words, if it is there to remove it). I know I can send a registry push with just the sites you want, and people can add later. What I want to do is to remove if it is there and keep the rest of the list intact.  I would like to have  ascript for this and run it regularly or at least on logon.


Thanks!!!!

How do I create an input box with a cancel button that will end a loop in my script?

$
0
0

I have been working on a script for my client and I am having trouble getting it to work properly. I stole most of the code from the PowerShell Tip of the Week "Creating a Custom Input Box". I also took someone's code for the Show-MessageBox function. I have slightly modified the original code with two parameters and an additional text box. The first field is for an e-mail address and the second is for an employee number.

I need to know how I can get a Do Until loop to recognize when the cancel button is pushed and break the loop and effectively end the script. The work happens at the end but perhaps I need something added/modified in the InputBox function.

I want the script to check to see if anything has been entered in the second text box. If empty it displays a message and calls the InputBox function again. Then if there is something I use elseif to check to see if it matches my RegEx (digits only). If it doesn't match it will loop and call the InputBox function again.

This all works fine. The problem I am having is that I cannot cancel out of the form. I'd like the loop to continue until the second box matches my RegEx or Cancel is clicked. Clicking cancel doesn't break the loop. I need to know how I can stop the loop when cancel is pressed. I've seen Stack "Overflow: PowerShell Cancel Button Stop Script" but I don't think this will work in a loop.

Any help would be awesome. As a note, I DO NOT want to use the VB Interaction stuff.

function InputBox { param ($Name,$EN) [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $objForm = New-Object System.Windows.Forms.Form $objForm.Text = "Data Entry Form" $objForm.Size = New-Object System.Drawing.Size(300,200) $objForm.StartPosition = "CenterScreen" $objForm.KeyPreview = $True $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") {$x=$objTextBox.Text;$objForm.Close()}}) $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$objForm.Close()}}) $OKButton = New-Object System.Windows.Forms.Button $OKButton.Location = New-Object System.Drawing.Size(75,120) $OKButton.Size = New-Object System.Drawing.Size(75,23) $OKButton.Text = "OK" $OKButton.Add_Click({$objForm.Close()}) $objForm.Controls.Add($OKButton) $CancelButton = New-Object System.Windows.Forms.Button $CancelButton.Location = New-Object System.Drawing.Size(150,120) $CancelButton.Size = New-Object System.Drawing.Size(75,23) $CancelButton.Text = "Cancel" $CancelButton.Add_Click({$objForm.Close()}) $objForm.Controls.Add($CancelButton) $objLabel = New-Object System.Windows.Forms.Label $objLabel.Location = New-Object System.Drawing.Size(10,20) $objLabel.Size = New-Object System.Drawing.Size(280,20) $objLabel.Text = "Employee Email Address:" $objForm.Controls.Add($objLabel) $objTextBox = New-Object System.Windows.Forms.TextBox $objTextBox.Location = New-Object System.Drawing.Size(10,40) $objTextBox.Size = New-Object System.Drawing.Size(260,20) if ($Name) { $objTextBox.Text = $Name } else { $objTextBox.Text = "@domain.com" } $objLabel2 = New-Object System.Windows.Forms.Label $objLabel2.Location = New-Object System.Drawing.Size(10,70) $objLabel2.Size = New-Object System.Drawing.Size(280,20) $objLabel2.Text = "Employee Number:" $objForm.Controls.Add($objLabel2) $objTextBox2 = New-Object System.Windows.Forms.TextBox $objTextBox2.Location = New-Object System.Drawing.Size(10,90) $objTextBox2.Size = New-Object System.Drawing.Size(260,20) $objForm.Controls.Add($objTextBox) $objForm.Controls.Add($objTextBox2) $objForm.Topmost = $True $objForm.Add_Shown({$objForm.Activate()}) [void] $objForm.ShowDialog() $Script:ButtonName = $objTextBox.Text $script:ButtonEN =$objTextBox2.Text $ButtonName; $ButtonEN } Function Show-MessageBox{ Param( [Parameter(Mandatory=$True)][Alias('M')][String]$Msg, [Parameter(Mandatory=$False)][Alias('T')][String]$Title = "", [Parameter(Mandatory=$False)][Alias('OC')][Switch]$OkCancel, [Parameter(Mandatory=$False)][Alias('OCI')][Switch]$AbortRetryIgnore, [Parameter(Mandatory=$False)][Alias('YNC')][Switch]$YesNoCancel, [Parameter(Mandatory=$False)][Alias('YN')][Switch]$YesNo, [Parameter(Mandatory=$False)][Alias('RC')][Switch]$RetryCancel, [Parameter(Mandatory=$False)][Alias('C')][Switch]$Critical, [Parameter(Mandatory=$False)][Alias('Q')][Switch]$Question, [Parameter(Mandatory=$False)][Alias('W')][Switch]$Warning, [Parameter(Mandatory=$False)][Alias('I')][Switch]$Informational) #Set Message Box Style IF($OkCancel){$Type = 1} Elseif($AbortRetryIgnore){$Type = 2} Elseif($YesNoCancel){$Type = 3} Elseif($YesNo){$Type = 4} Elseif($RetryCancel){$Type = 5} Else{$Type = 0} #Set Message box Icon If($Critical){$Icon = 16} ElseIf($Question){$Icon = 32} Elseif($Warning){$Icon = 48} Elseif($Informational){$Icon = 64} Else{$Icon = 0} #Loads the WinForm Assembly, Out-Null hides the message while loading. [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null #Display the message with input $Answer = [System.Windows.Forms.MessageBox]::Show($MSG , $TITLE, $Type, $Icon) #Return Answer Return $Answer } $num = "^\d+$" do { if (!($ButtonEN)) { Show-MessageBox -Msg "You must enter a numeric value for the employee number." -Title "Employee Number Missing" -Critical InputBox -Name $ButtonName } elseif ($ButtonEN -notmatch $num) { Show-MessageBox -Msg "The employee number must contain numbers only!" -Title "Non-numerical characters found" -Critical InputBox -Name $ButtonName } } until (

($ButtonEN -match $num) -or (<this is where I want to be able to use the cancel button>) )



Need to automate Powershell using Powerpoint creating PDF

$
0
0

I've got a Windows 7 (64-bit) machine and I'm trying to use the built-in Powershell to automate PowerPoint 2010 to create PDFs from PPT and PPTX files in a folder.

I want this to run without GUI and create a single file.

Unfortunately, all I've been able to achieve is something that brings up the GUI and saves each page as it's own jpg in a sub-folder.

Does anyone have a short script that can do this? 


Careful with that VAX Eugene

PS Get-Content - file containing environement variable

$
0
0

Hello

I have an issue with a script where I have a text file containing folders and files. I get them with Get-Content and then I copy them somewhere else.

My problem is that I would like to be able to use environement variable in the text file, like D:\$env:USERNAME\Documents but when I get them through Get-Content, variable are not converted.

Is there a way to make Powershell recognizing variables in the path ?

Thanks !

deploying a change in hosts file

$
0
0

Hi

I have a script that adds new entries in the hosts file. I want to deploy it in several machines, with no admin rights and with O.S. Windows 8.1

The problem is that UAC is needed and always prompt for an admin user. I would like a solution, scripting or whatever that can deploy this without admin intervention.

Thanks in advance.


Viewing all 15028 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>