Manual's PowerShell Script

How have other people followed along with the lab manuals?  Anytime a commandlet begins the PowerShell they are having you do there is bold letters written over italic letters.  I feel I am playing a guessing game that is inhibiting me rather
then letting me learn.  Did you export the file to another format or just keep guessing?

Hi Bryan,
Could you clarify your question? What the problem you have meet now? If you want to change the PowerShell Console “appearance” you can refer the following KB:
Customizing the Windows PowerShell Console
http://technet.microsoft.com/en-us/library/ee156814.aspx
I’m glad to be of help to you!
We
are trying to better understand customer views on social support experience, so your participation in this
interview project would be greatly appreciated if you have time.
Thanks for helping make community forums a great place.

Similar Messages

  • Using Echo Command in PowerShell Script for Configuration Item

    Hello All,
    Before you tell me to post my PowerShell question to the PowerShell Forum, please know that the PowerShell portion of my task works just fine. It is the SCCM portion of my task that keeps failing, so that is why I am here. To give some background...
    There are two servers in our SCCM test environment. Both the SCCM server and SQL DB server are 2012, patched and updated.
    Test servers in my Device Collection being used for running Baselines and Reports against are 2008R2 and 2012, patched and updated.
    I have created a Configuration Item that checks to see if the FTP Server Role Feature has been installed on a 2008 or 2012 server. To do the check, I am using the following PowerShell script:
    (get-windowsfeature -Name Web-Ftp-Server).Installed
    When I log into my 2008R2 and 2012 test servers, and run this command directly on the server, it will return a "True" if the FTP Server Role Feature is installed on either server, and a "False" if it is not installed. Basically,
    it works as advertised.
    When I setup my Configuration Item and then deploy my Baseline, or run a report against my device collection of test servers, SCCM will return a correct response (True or False) for the 2012 test server, but throws the following error for the 2008R2
    server:
    0x87df00329 application requirement evaluation or detection failed
    Google searches for this have not been very helpful.
    Now, when I created the Configuration Item and referenced PowerShell, the configuration screen has the following note:
    "Specify the script to find and return the value to be assessed for compliance on client devices. Use the echo command to return the script value to Configuration Manager."
    Since I did not include an echo command in my PowerShell script above, I figured that was my problem, so I did the following:
    Logging onto both of my test servers (2008R2 & 2012) I was able to successfully run the following PowerShell commands and get the expected responses of True or False:
    (get-windowsfeature -Name Web-Ftp-Server).Installed | echo
    (get-windowsfeature -Name Web-Ftp-Server).Installed | write-output (http://technet.microsoft.com/en-us/library/hh849921.aspx)
    (get-windowsfeature -Name Web-Ftp-Server).Installed | write-host (http://technet.microsoft.com/en-us/library/ee177031.aspx)
    However, when I use any of these PowerShell commands in my Configuration Item, NEITHER of my test servers returns a response to the SCCM server.
    When I check the report, both servers show as "Unknown" and when I click on the number 2 (as in 2 servers unknown), the following report page (List of unknown assets for a configuration baseline) has absolutely no data/information at all.
    So...I am at a loss.
    SCCM tells me to use an echo command to return a script value to Configuration Manager. The PowerShell scripts above, with the various echo related commands, work just fine on the servers themselves, but they return no information when run via SCCM.
    What am I missing?
    Any help will be appreciated.
    Thanks in advance for your time.

    Sorry for my ignorance, but I don't understand. (I forgot to mention that I am new at both PowerShell and SCCM.)
    After I change the PowerShell script to add the echo/write-output/write-host cmdlet, I open the ConFig Item and "Clear" the PowerShell script and then re-add it. When I do that, it correctly shows the change in the ConFig Item.
    Next I open the Baseline, then open the ConFig Item within the Baseline to make sure the change is reflected there as well, which it is.
    I then deploy the Baseline to my Device Collection. After that, I run a report against the Baseline and Device Collection and it returns the "Unknown" result.
    If I open the PowerShell script and remove the echo/write-output/write-host cmdlet, then go through the rest of the process of updating and reporting, the result it returns changes, showing one server in compliance and the other server out of compliance,
    which leads me to think that all changes have taken correctly.
    Does that sound right? If I manually deploy the Baseline, is that the same as the client retrieving policies from the management point?
    Sorry to be so thick but I'm learning as I go.
    Thanks again for your help.

  • PowerShell Scripting help to combine two scripts

    I have a script that helps automate virtual server builds.  The script creates a specification document which is used to perform the actual builds.
    # Spec-And-Build.ps1 - Loops through a directory and performs an
    # end to end specification generation and build on each request in that directory
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true)]
        [string]$RequestDir,
        [Parameter(Mandatory=$true)]
        [string]$SpecDir,
        [Parameter(Mandatory=$false)]
        [pscredential]$Credential_CPR,
        [Parameter(Mandatory=$false)]
        [pscredential]$Credential_VDC,
        [Parameter(Mandatory=$false)]
        [pscredential]$Credential_Admin
    if (!$Credential_CPR) {
        $Credential_CPR = Get-Credential -Message "CPR Domain Credentials."
        if (!$Credential_CPR.UserName.ToUpper().StartsWith("CPR\")) {
            $Credential_CPR = New-Object pscredential(
                ("CPR\" + $Credential_CPR.UserName), $Credential_CPR.Password)
    if (!$Credential_VDC) {
        $Credential_VDC = Get-Credential -Message "VDC Domain Credentials."
        if (!$Credential_VDC.UserName.ToUpper().StartsWith("VDC\")) {
            $Credential_VDC = New-Object pscredential( `
                ("VDC\" + $Credential_VDC.UserName), $Credential_VDC.Password)
    if (!$Credential_Admin) {
        $Credential_Admin = Get-Credential -UserName "Administrator or root" `
            -Message "Enter the Administrator or root password for the new VM. The user name here will be ignored"
    .\Gen-VMSpec-Many.ps1 -RequestDir $RequestDir -SpecDir $SpecDir -Credential_VDC $Credential_VDC
    $caption = "Continue Build"
    $message = "Please validate the generated specification files in $SpecDir - Then click Continue to start build"
    $opContinue = new-Object System.Management.Automation.Host.ChoiceDescription "&Continue","help"
    $opAbort = new-Object System.Management.Automation.Host.ChoiceDescription "&Abort","help"
    $choices = [System.Management.Automation.Host.ChoiceDescription[]]($opContinue,$opAbort)
    $answer = $host.ui.PromptForChoice($caption,$message,$choices,0)
    if ($answer -eq 0) {
        .\Build-VM-Many.ps1 -SpecDir $SpecDir -Credential_CPR $Credential_CPR -Credential_VDC $Credential_VDC -Credential_Admin $Credential_Admin
    } else {
        Write-Host "Build step aborted, run Build-VM-Many.ps1 manually to continue."
    This script works well.  Now I need to add a section that adds Active Directory groups to the built servers from the spec document.  I found this script which also works well:
    # Create local group on the local or a remote computer 
    Write-Host -foregroundcolor Yellow 'Admin Privileges Required!' 
    $computerName = Read-Host 'Enter computer name or press <Enter> for localhost' 
    $localGroupName = Read-Host 'Enter local group name' 
    $description = Read-Host 'Enter description for new local group' 
    if ($computerName -eq "") {$computerName = "$env:computername"} 
    if([ADSI]::Exists("WinNT://$computerName,computer")) { 
        $computer = [ADSI]"WinNT://$computerName,computer" 
        $localGroup = $computer.Create("group",$localGroupName) 
        $localGroup.SetInfo() 
        $localGroup.description = [string]$description 
        $localGroup.SetInfo() 
    My question is, how do I make one script from the two?  I am very new to PowerShell scripting.

    Here are the instructions on how to use PowerShell:
    http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx
    Your question is vague and is asking for someone to do this for you.  It is better if you do it yourself and post back with specific questions.
    In the end you have to write and debug the scripts. We will not do this for you but we will answer questions.
    ¯\_(ツ)_/¯

  • PowerShell Script running Excel won't run on Windows Server 2008 R2

    I have a script that creates a report of a single example of each warning or error in the Windows Event log, for each server in a list of servers,with the number of times that error has occurred in the last week on each server. It creates this report in
    Excel. I have this script running automated through Task Scheduler for one client on Windows 7 and it's working perfectly. I have another client that I am attempting to run this script automated on a server running Windows Server 2008 R2. I can manually run
    the script and everything works, but if I try to schedule the script everything works except for the Excel PowerShell commands. I've have tried:
    Created the Desktop folders for config\systemprofile in System32 and in SysWOW64.
    Configured permissions in DCOM for Microsoft Excel Application.
    Configured folder permissions for config\systemprofile.
    Verified PowerShell is working.
    Unchecked the option in the task to only run while logged on.
    Does anyone have any idea why this is happening and how I can fix it? Thanks!
    Sincerely,
    Christopher Beard

    You might have to launch the application once as the system account so that it can set up the Excel environment, I've had the same problem when  trying to update Excel files from an admin Powershell console using my admin account.  Use psexec with
    a -s option to run it as system account locally while logged on to the target server:
    psexec -s "c:\program files (x86)\microsoft office\office14\excel.exe"
    Then you'll most likely be prompted to input initials - which is what I suspect is preventing your code from running properly.
    There may be some other more elegant way to handle this, but you'd be better off asking that question in one of the forums devoted to Office products.
    I hope this post has helped!

  • PowerShell script : Directory object not found error in Get-ADGroupMember

    I am new in powershell scripting. I am writing a script to add users in different AD Groups. while doing so I do the following:
    Check if the user already exist in the group:
    $mbr_exist = Get-ADGroupMember $grpname | Where-Object {$_.SamAccountName -eq $sam}
    If user does not exist then add the user to the group.
    When I manually run the script its runs flawless, without any errors. But when I schedule the script to run it gives an error as follows:
    3/30/2015 8:32:15 AM Directory object not foundAt + $mbr_exist = Get-ADGroupMember $grpname | Where-Object {$_.SamAc ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~ Error at Line:$mbr_exist = Get-ADGroupMember
    $grpname | Where-Object {$_.SamAccountName -eq $sam}
    The strange thing is the user for which it throws the error is present in the group.I am not sure why this error is occurring when scheduled. Can any one please help? All the suggestions will be appreciated
    Note: (The script is scheduled using Windows Task Scheduler)
    try
    # # Initialize the variables we will use
    $status = 'false'
    $drivename = "H:"
    $sysdate = Get-Date -UFormat "%m_%d_%Y"
    $foldername = $drivename + "\Script_Result\PowershellData"+ $sysdate
    $backup_folder = "$foldername\AD_Groups_Backup"
    $updatedGroup = "$foldername\Updated_AD_Groups_LogFiles"
    $LogFilePath = "$foldername\Log_Update_ADGroups"+$sysdate+".log"
    # # Initialize the arrays we will use
    $GroupArray = @()
    # # maintain log of program startup
    $logdate = get-date
    $logdate.ToString() + "`tStarted script to Update AD user Groups..." | Out-File -FilePath $LogFilePath
    # # Create a sub folder to store the backup files
    $fileexist = Test-Path $backup_folder -PathType Container
    if($fileexist -ne 'False')
    New-Item -ItemType Directory $backup_folder
    # # Create a sub folder to store Updated AD group Log files
    $fileexist = Test-Path $updatedGroup -PathType Container
    if($fileexist -ne 'False')
    New-Item -ItemType Directory $updatedGroup
    # # Take back up of the AD groups data
    Get-ADGroupMember -Identity "Group1" | Export-csv "$backup_folder\Group1_BackUP$sysdate.csv"
    Get-ADGroupMember -Identity "Group2" | Export-csv "$backup_folder\Group1_BackUP$sysdate.csv"
    Get-ADGroupMember -Identity "Group3" | Export-csv "$backup_folder\Group1_BackUP$sysdate.csv"
    Get-ADGroupMember -Identity "Group4" | Export-csv "$backup_folder\Group1_BackUP$sysdate.csv"
    (an so on..... 11 such groups )
    # # Fetch AD Users data
    $ADusers = Get-ADUser -filter {(EmployeeNumber -gt 1) -and (EmployeeNumber -ne "N/A") -and (Enabled -eq $true)} -Properties * | Sort-Object -Property EmployeeNumber
    $ADusers.Count
    foreach($u in $ADusers)
    $sam = $u.SamAccountName
    $empnum = $u.EmployeeNumber
    $mgr = $u.mgr
    $fsal = $u.'fsalary-Hourly'
    $comp = $u.Company
    $ofc = $u.Office
    Write-Host "$sam : $empnum : $mgr :$fsal : $comp : $ofc" -ForegroundColor Yellow
    $GroupArray = @()
    # # Check if the user fits in any of the 11 scenarios
    if($comp -eq "US")
    # scenario 7
    write-host "7. Add to US Employees"
    $GroupArray += "US Employees"
    if($mgr -eq "Y")
    Write-Host "1. ADD to US MAnagers"
    $group = "US Managers"
    $GroupArray += $group
    if(($fsal -eq "Hourly") -and ($ofc -ne "Canton"))
    Write-Host "3. Add to US Hourly (excluding Canton)"
    $group = "US Hourly (excluding Canton)"
    $GroupArray += $group
    if(($fsal -eq "Hourly") -and ($ofc -eq "Canton"))
    write-host "4. Add to US Canton Hourly"
    $group = "US Canton Hourly"
    $GroupArray += $group
    if(($fsal -eq "Salaried") -and ($ofc -eq "Corporate" -or $ofc -eq "Landis Lakes 1" -or $ofc -eq "Landis Lakes 2"))
    Write-Host "5. Add to US Salaried Corporate"
    $group = "US Salaried Corporate"
    $GroupArray += $group
    if(($fsal -eq "Salaried") -and ($ofc -ne "Corporate" -and $ofc -ne "Landis Lakes 1" -and $ofc -ne "Landis Lakes 2"))
    Write-Host "6. Add to US Salaried Plant"
    $group = "US Salaried Plant"
    $GroupArray +=$group
    elseif($comp -eq "canada")
    # scenario 9
    write-host "9. Canada Employees"
    $GroupArray += "Canada Employees"
    if($mgr -eq "Y")
    Write-Host "2. Add to Canada Managers"
    $group = "Canada Managers"
    $GroupArray += $group
    if($fsal -eq "Hourly")
    Write-Host "10. Add to Canada Hourly"
    $group = "Canada Hourly"
    $GroupArray += $group
    if($fsal -eq "Salaried")
    Write-Host "11. Add to Canada Salaried Plant"
    $group = "Canada Salaried Plant"
    $GroupArray += $group
    elseif($ofc -eq "Corporate" -or $ofc -eq "Landis Lakes 1" -or $ofc -eq "Landis Lakes 2")
    Write-Host "8. Add to Corporate Employees"
    $GroupArray += "Corporate Employees"
    write-host "Final Group List" -ForegroundColor Green
    $grplen = $GroupArray.Length
    #$GroupArray
    $grplen
    for($i= 0; $i -lt $grplen; $i++)
    $grpname = $GroupArray[$i]
    write-host "$sam will be added to Group : $grpname" -ForegroundColor Magenta
    # # Check if the user is already present in the Group
    $mbr_exist = Get-ADGroupMember $grpname | Where-Object {$_.SamAccountName -eq $sam}
    if($mbr_exist -eq $null)
    # #Add user to US Managers group
    Add-ADGroupMember -Identity $grpname -Members $sam
    Write-Host "1. User $sam is added to $grpname group" -ForegroundColor Green
    # # documenting the user list that are added to this group
    $grpmbr = New-Object PSObject
    $grpmbr | Add-Member -MemberType NoteProperty -Name "EmployeeNumber" -Value $empnum
    $grpmbr | Add-Member -MemberType NoteProperty -Name "SamAccountName" -Value $sam
    $grpmbr | Add-Member -MemberType NoteProperty -Name "Name" -Value $u.Name
    $grpmbr | Add-Member -MemberType NoteProperty -Name "DistinguishedName" -Value $u.DistinguishedName
    $grpmbr | Add-Member -MemberType NoteProperty -Name "mgr" -Value $mgr
    $grpmbr | Add-Member -MemberType NoteProperty -Name "Company" -Value $comp
    $grpmbr | Add-Member -MemberType NoteProperty -Name "Salary/Hourly" -Value $fsal
    $grpmbr | Add-Member -MemberType NoteProperty -Name "Office" -Value $ofc
    $grpmbr | Add-Member -MemberType NoteProperty -Name "ADGroup" -Value $grpname
    $grpmbr | Export-Csv "$updatedGroup\ADUsers_To_Group($grpname)_$sysdate.csv" -Append -NoTypeInformation
    else
    Write-Host "Member $sam already exist in $grpname group" -ForegroundColor Red
    $logdate = get-date
    $logdate.ToString() + "`tCompleted script to Update Update AD Groups..." | Out-File -FilePath $LogFilePath -Append
    $status = 'true'
    return $status
    catch
    $err_lineno = $error[0].InvocationInfo.ScriptLineNumber
    $err_line = $error[0].InvocationInfo.Line
    $ExceptionMessage = $_.Exception.Message
    #$ExceptionMessage
    $error_info = $error[0].ToString() + $error[0].InvocationInfo.PositionMessage
    Write-Host "$error_info " -ForegroundColor Red
    $FailedItem = $_.Exception.ItemName
    if($ExceptionMessage)
    $logdate.ToString() + "`t $error_info " | out-file "$foldername\ErrorLog_Update_AD_Groups$sysdate.log" -append
    "Line Number: $err_lineno . `nError at Line: $err_line" | out-file "$foldername\ErrorLog_Update_AD_Groups$sysdate.log" -append
    #Invoke-Item "C:\ErrorLog.log"
    $status = 'false'
    return $status

    Hi mdkelly, Sorry for such a late reply (due to credential issues).
    I am using Windows task scheduler to schedule the task. I am given the administrator access to the server (Windows Server 2012). So I think I set to run the script under system account.
    My apologies for asking this, am I missing something while scheduling the script through task scheduler?  how to check if the scheduled task is running under who's credentials? How to pass my (admin) credentials, so that the script execution won't face
    a problem? Any suggestion on the above questions will be helpful. (I tried to search on net for the questions but didn't get any conclusive answers)  
    Thanks in advance.

  • Powershell script to update mailbox search

    I am trying to update a mailbox search using a powershell script:
    Stop-MailboxSearch -Identity "LitHolds" -confirm:$false
    $members = (import-csv -Path "Path"| ForEach-Object{$_.SamAccountName})
    foreach ($user in $members)
    Set-MailboxSearch -Identity "LitHolds" -SourceMailboxes $user.samaccountname
    Start-MailboxSearch -Identity "LitHolds" -confirm:$false
    I essentially have our sysadmins populating a csv file and then they run this script manually every night with the latest updates.  They are telling me that the mailbox search is empty.
    When I run the script I am getting a watson error immediately after with the following:
    WARNING: An unexpected error has occurred and a Watson dump is being generated: Value cannot be null.
    Parameter name: legacyDN
    Value cannot be null.
    Parameter name: legacyDN
        + CategoryInfo          : NotSpecified: (:) [Stop-MailboxSearch], ArgumentNullException
        + FullyQualifiedErrorId : System.ArgumentNullException,Microsoft.Exchange.Management.Tasks.StopMailboxSearch
        + PSComputerName        : Exchange Server Name
    What I don't understand is why it's looking for a legacyDN??
    Anyone able to do something similar?
    Chuck

    Hi Chuck,
    I would like to verify if you have a legacy Exchange.
    The LegacyDN property indicates the legacyDN of the mailbox and matches the legacyExchangeDN attribute of the user object in  Microsoft Active Directory.
    If there is any update, please feel free to let me know.
    Best regards,
    Amy
    Amy Wang
    TechNet Community Support

  • How to insert the file name to the start and the end of a SQL file by a powershell script

    I just began to learn powershell script and I have a problem that I cannot figure out. I have a lot of .sql files. I need to insert its file name to the beginning of the file (After USE statement) and the end of the file (before the last END statement). Is
    there anybody knowing how to do this?
    Thanks so much
    Regards

    Actually, I want to add a insert SQL statement to the beginning of the file and the end of the file. Only the file name is a variable and different among
    different files. All the other sql statements are the same and can be hard coded. Hopefully it helps –
    The problem I think is that I want to add the same thing (except the file name) to hundreds of sql files and only the file name is different. I do not want
    to add it manually and want to use a script to add it – 

  • System.Drawing.Bitmap in a scheduled powershell script

    I've written a powershell script to date stamp multipage tiffs, but I check to make sure the file name follows the correct format before doing so. The file name must contain the date, sequence number, and number of pages. The script works fine when run manually,
    but when run from task scheduler it fails to query the number of pages in the TIFF. Any ideas why the .NET features wouldn't work from a powershell script run as a scheduled task?
    I am putting the page number in the variable "count" by doing the following:
     $i=[System.Drawing.Bitmap]::FromFile($file.Fullname);$i.GetFrameCount($i.FrameDimensionsList[0]) 
     $count=$i.GetFrameCount([System.Drawing.Imaging.FrameDimension]::Page)
    FULL SCRIPT FOLLOWS
    #Define the input and output folders and date format
    $Original_TIFFs="C:\scans"
    $Modified_TIFFs=";\\test\Shared\SDS\"
    $date = get-date -Format d
    $datename=Get-Date -format yyyyMMdd
    Set-Location $Original_TIFFs
    #Configure email settings
    $emailFrom = "removed"
    $emailTo = "removed"
    $smtpServer = "removed"
    $body = "Rename scanned claims file to the correct format. This email was sent from: ", $env:computername
    #Define the location of the TIFF command line executable and its parameters
    $200DLL='C:\TiffDLL200Commandline\Cmd200.exe '
    $arg1='"FILE='
    #Modify arg2 to put the output directory in front of the ; if don't want to overwrite current file
    #$arg2=';|OW=Yes|BITS=2|TEXT=2;Received Date: '
    $arg2=$modified_TIFFs
    $arg3=';|BITS=2|TEXT=2;Received Date: '
    $arg4='|TEXTOPS=-5;;10;14;"'
    $files=Get-ChildItem $Original_TIFFs -Filter *.tif
    if ($files -eq $null)
      $subject = "No files to process today, directory empty."
      $smtp = new-object Net.Mail.SmtpClient($smtpServer)
      $body = "No files were processed today. This email was sent from: ", $env:computername
      $smtp.Send($emailFrom, $emailTo, $subject, $body)
    else
    foreach ($file in $files)                                                                  
       #Begin loop to check each file and process
     #Loads subsystems for opening TIFFs and second line puts the number of images into variable
     $i=[System.Drawing.Bitmap]::FromFile($file.Fullname);$i.GetFrameCount($i.FrameDimensionsList[0]) 
     $count=$i.GetFrameCount([System.Drawing.Imaging.FrameDimension]::Page)
     #If statement checks if filename format is correct
     if ($file -match '^\d{8}\d{3}_H_S_\d+_\d{8}[.tif]{4}$')
      $file.name -match '^(?<date1>\d{8})\d{3}_H_S_(?<page_count>\d+)_(?<date2>\d{8})[.tif]{4}$'   #Regex to put tests in $matches to check against
      if (($matches.date1 -eq $datename) -and ($matches.date2 -eq $datename))                      #Check if filename contains correct date
      if ($count -eq $matches.page_count)                                                          #Check if filename
    contains the correct page count
       #insert TIFF modification
        $allargs=$200Dll+$arg1+$file+$arg2+$file+$arg3+$date+$arg4
        cmd /c $allargs
        #cmd /c xcopy $file \\test\shared\SDS                                                   #Deprecated because now having
    TIFF200DLL create a new file rather than overwrite
        $i.Dispose()                                                                  
                #Close file stream so file can be deleted: http://support.microsoft.com/kb/814675
        Remove-Item $file.Name
        #Next section is for a different output directory; Setup a seperate batch file to delete original TIFFs in the middle of the night
        <#
        $allargs="cmd200 "+$arg1+$file+";"+$Modified_TIFFs+";"+$arg2+$date+$arg3
        cmd /c $allargs
        #>
        else                                                                    
                     #else statement to send out error message if the number of pages differs from name
        $subject = "The number of pages in the file ", $file.FullName, "differs from the actual count of ", $count, ". File will not be sent, please correct before tomorrow for processing."
        $smtp = new-object Net.Mail.SmtpClient($smtpServer)
        $smtp.Send($emailFrom, $emailTo, $subject, $body)
      }  #Close IF/THEN for correct date is in filename
     else
        $subject = "Date portion of filename is incorrect, please fix. File will not be sent to SDS", $file.FullName," ."
        $smtp = new-object Net.Mail.SmtpClient($smtpServer)
        $smtp.Send($emailFrom, $emailTo, $subject, $body)
     }                                                    #Close IF/THEN for initial filename check
     else
        $subject = "File does not meet proper naming convention and will not be stamped nor sent to SDS", $file.FullName, " ."
        $smtp = new-object Net.Mail.SmtpClient($smtpServer)
        $smtp.Send($emailFrom, $emailTo, $subject, $body)
    }                                                     #Close FOR loop
    }                                                     #Close Else for check if FILES=NULL

    You are buikding thisin the ISE?
    You need too add:
    add-type -AssemblyName System.Drawing
    ¯\_(ツ)_/¯

  • Compliance Settings Adobe flash Player disable Automatic Updates Powershell Scripts fail

    Hello,
    I have setup compliance to check and remediate if Adobe flash Player automatic updates is enabled by using PowerShell scripts.
    If I run the scripts below manually on my pc they work fine, but if I run in sccm 2012 compliance I get:
    Setting Discovery Error
    0x87d00327
    Script is not signed
    CCM
    I tried contacting the person that created the scripts, but didn't get a response.
    Discovery Script
    Set-ExecutionPolicy Unrestricted -force
    <#
      This script will check if automatic updates is disabled and return a Compliant/Non-Compliant string.
      Created:     04.08.2014
      Version:     1.0
      Author:      Odd-Magne Kristoffersen
      Homepage:    https://sccmguru.wordpress.com/
      References:
      - Configure auto-update notification Flash Player
    http://helpx.adobe.com/flash-player/kb/administration-configure-auto-update-notification.html
      - Adobe Flash Player Administration Guide for Flash Player 14
    http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/flashplayer/pdfs/flash_player_14_0_admin_guide.pdf
      - Adobe Flash Player Administration Guide for Microsoft Windows 8
    http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/flashplayer/pdfs/flash_player_13_0_admin_guide.pdf
    #>
    $OSArchitecture = Get-WmiObject -Class Win32_OperatingSystem | Select-Object OSArchitecture
    If($OSArchitecture.OSArchitecture -ne "32-bit")
        $CFGExists = Test-Path -Path "$Env:WinDir\SysWow64\Macromed\Flash\mms.cfg"
             if($CFGExists -eq $True)
             {$UpdateCheck = Select-String "$Env:WinDir\SysWow64\Macromed\Flash\mms.cfg" -pattern "AutoUpdateDisable=1" | Select-Object Line}
                if($UpdateCheck.Line -eq 'AutoUpdateDisable=1') {Write-Host 'Compliant'}
                else {Write-Host 'Non-Compliant'}
    else
        $CFGExists = Test-Path -Path "$Env:WinDir\System32\Macromed\Flash\mms.cfg"
             if($CFGExists -eq $True)
             {$UpdateCheck = Select-String "$Env:WinDir\System32\Macromed\Flash\mms.cfg" -pattern "AutoUpdateDisable=1" | Select-Object Line}
                if($UpdateCheck.Line -eq 'AutoUpdateDisable=1') {Write-Host 'Compliant'}
                else {Write-Host 'Non-Compliant'}
    Remediation Script
    Set-ExecutionPolicy Unrestricted -force
    <#
      This script will check if automatic updates is disabled and return a Compliant/Non-Compliant string.
      Created:     04.08.2014
      Version:     1.0
      Author:      Odd-Magne Kristoffersen
      Homepage:    https://sccmguru.wordpress.com/
      References:
      - Configure auto-update notification Flash Player
    http://helpx.adobe.com/flash-player/kb/administration-configure-auto-update-notification.html
      - Adobe Flash Player Administration Guide for Flash Player 14
    http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/flashplayer/pdfs/flash_player_14_0_admin_guide.pdf
      - Adobe Flash Player Administration Guide for Microsoft Windows 8
    http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/flashplayer/pdfs/flash_player_13_0_admin_guide.pdf
    #>
    $OSArchitecture = Get-WmiObject -Class Win32_OperatingSystem | Select-Object OSArchitecture
    If($OSArchitecture.OSArchitecture -ne "32-bit")
        $CFGExists = Test-Path -Path "$Env:WinDir\SysWow64\Macromed\Flash\mms.cfg"
             if($CFGExists -eq $True)
             {$UpdateCheck = Select-String "$Env:WinDir\SysWow64\Macromed\Flash\mms.cfg" -pattern "AutoUpdateDisable=1" | Select-Object Line}
                if($UpdateCheck.Line -eq 'AutoUpdateDisable=1') {Write-Host 'Compliant'}
                else {Write-Host 'Non-Compliant'}
    else
        $CFGExists = Test-Path -Path "$Env:WinDir\System32\Macromed\Flash\mms.cfg"
             if($CFGExists -eq $True)
             {$UpdateCheck = Select-String "$Env:WinDir\System32\Macromed\Flash\mms.cfg" -pattern "AutoUpdateDisable=1" | Select-Object Line}
                if($UpdateCheck.Line -eq 'AutoUpdateDisable=1') {Write-Host 'Compliant'}
                else {Write-Host 'Non-Compliant'}
    Thanks,
    Mark

    Hi Jeff,
    You were correct, Default client settings was set to All signed and once I set to bypass, PowerShell Scripts executed.  But now I am getting:    If I run them both from PowerShell, they work fine. Thanks again for your help, Mark
    Error Type
    Error Code
    Error Description
    Error Source
     Enforcement Error
    0x87d00329
    Application requirement evaluation or detection failed
    CCM

  • Issue with AD Powershell Script

    Matt338 wrote:This returned that I had two 1st OU's.
    It was what I was looking for.
    cduff wrote:
    it will work without manually specifying the DN property, because the OU object will implicitly cast to a DN string
    As I always passed the object and never the DN, I made in my head an implicit definition of the needed type for the targetpath argument :D

    So I have been working this summer getting ready for the next school year. I need to move all of my students up and I thought this would be a great job for a PowerShell script. So I did a little research and found the commands and added the -whatif tag so I could test my scripting. It worked and I was happy.Fast forward now two months and I went to run the script once yesterday and I received some errors for the first six lines the the remaining seven ran just fine.Here is my script:Powershellget-aduser -filter "description -eq 'grad27'" | move-adobject -targetpath (Get-ADOrganizationalUnit -filter "name -eq '1st'") -whatifget-aduser -filter "description -eq 'grad26'" | move-adobject -targetpath (Get-ADOrganizationalUnit -filter "name -eq '2nd'") -whatifget-aduser -filter "description -eq 'grad25'" | move-adobject -targetpath (...
    This topic first appeared in the Spiceworks Community

  • I'm trying to run a scheduled task as system, but it will not run my powershell script

    I have a powershell script I created that uses credentials within the script to connect to a network resource to copy files every night. It works fine if I just run the script manually. but I need to run this as a scheduled task, preferably as system. I
    have checked "run with highest privileges" still no luck. 
    If I change the user to my account it works fine, but I need it to work without the use of my account. Is this some kind of security policy problem or what would cause this? I figure having the credentials within the script would work, but not so much.
    Paul Arbogast

    I have a powershell script I created that uses credentials within the script to connect to a network resource to copy files every night. It works fine if I just run the script manually. but I need to run this as a scheduled task, preferably as system. I
    have checked "run with highest privileges" still no luck. 
    If I change the user to my account it works fine, but I need it to work without the use of my account. Is this some kind of security policy problem or what would cause this? I figure having the credentials within the script would work, but not so much.
    Paul Arbogast
    Is the Execution Policy set for the script?
    With this information it sounds to be.....
    Take a look @
    http://technet.microsoft.com/en-us/library/ee176961.aspx
    Best Wishes,

  • Workflow does not start when PowerShell Script is run from Task Scheduler

    I have a PS script that updates an item in a SP2010 list so that a workflow will be started.  When I run the PS script manually from the PS window on the server it resides, the script runs flawlessly.  If I set a scheduled task on the same server
    to run the script with the same credentials as are being used in the PS window, the script runs, updated the info on the list, but DOES NOT start the workflow.  As we know, SPD workflows cannot be started by anonymous or system accounts.  It is as
    if the task scheduler adds a bit of information that makes the SP2010 list think the information was updated by one of these accounts even though the field in the list for the item being updated shows the correct account.
    HELP!!!
    D

    Hi,
    The issue might be related to the script or schedule task settings your configured. You’d better check the settings.
    For example, which option do you set to run the scheduled task? You may select “Run whether user is logged on or not” instead of “run only when user is logged on” as shown in this article:
    http://blog.pointbeyond.com/2010/04/23/run-powershell-script-using-windows-server-2008-task-scheduler/
    Hope it helps.
    Best Regards,
    Sally Tang

  • How to make the width of powershell script's output greater than 80 column?

    Hi,
    I am trying to remotely execute a powershell script through ssh, and I found the output of my script is only 80 width, a carriage-return and a line-feed are inserted after 79th column, and continue presenting the 80th value of each row onto another line.
    I want it greater than 80, such as 512.
    The code to print the output in my script is like:
    $allInfo | ConvertTo-Xml -as Stream -NoTypeInformation -Depth 1
    Any help will be really appreciated!

    But when I run the powershell script manually, I get the following error message, I do not know why, but anyway, my problem is resolved.
    Exception setting "BufferSize": "Cannot set the buffer size because the size specified is too large or too small.           
    Parameter name: value                                                                                                       
    Actual value was 512,25."                                                                                                   
    At C:\Users\qzhang\Documents\GetVM.ps1:30 char:16                                                                           
    + $Host.UI.RawUI. <<<< BufferSize = New-Object Management.Automation.Host.Size (512, 25)                                    
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException                                                    
        + FullyQualifiedErrorId : PropertyAssignmentException  
    Yeah, that's a good question.  I get the same thing here.  The longer solution the post covers which I've included below does work interactively, and looking at the differences it appears to be related to the buffer height.  My guess is when
    the existing console window already has more rows in the buffer than the 25 rows in height the command tries to define, this error occurs.
    if( $Host -and $Host.UI -and $Host.UI.RawUI ) {
    $rawUI = $Host.UI.RawUI
    $oldSize = $rawUI.BufferSize
    $typeName = $oldSize.GetType( ).FullName
    $newSize = New-Object $typeName (500, $oldSize.Height)
    $rawUI.BufferSize = $newSize

  • Powershell script to help fix broken WMI on remote servers/computer.

    I have a number of servers/computers that I am not able to update due to broken WMI. Does anyone out there have a Powershell script that will stop the WMI service, rename the repository and logs folders, then restart the WMI service again?
    I created a script to stop the service, but it will not allow me to rename the folders (tells me access denied). If I dameware into the pc and log in with my admin credentials I have no issues manually doing the above steps, but there has to be an easier
    way!
    Any help would be greatly appreciated.

    To remotely rename folders you must use an admin account on the remote system. The folder must not be protected the system and you cannot us WMI to rename the folder.
    You may have to restart the system after setting WMI to manual start as it can have locks and it may not shutdown cleanly.
    ¯\_(ツ)_/¯

  • PowerShell script doesn't appear to work as scheduled task in sharepoint 2013

    PowerShell script doesn't appear to work as scheduled task in sharepoint 2013, it works as normal manual execution
    MCTS Sharepoint 2010, MCAD dotnet, MCPDEA, SharePoint Lead

    Hi,
    To run PowerShell Script as scheduled task in SharePoint 2013, you can take the demo below for a try:
    http://blogs.technet.com/b/meamcs/archive/2013/02/23/sharepoint-2013-backup-with-powershell-and-task-scheduler-for-beginners.aspx
    Thanks
    Patrick Liang
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support,
    contact [email protected]
    Patrick Liang
    TechNet Community Support

Maybe you are looking for

  • Query takes a long time on EBAN table

    Hi, I am trying to execute a simple select statement on EBAN table. This query takes unexpectionally longer time to execute. Query is : SELECT banfn bnfpo ernam badat ebeln ebelp       INTO TABLE gt_eban       FROM eban FOR ALL ENTRIES IN gt_ekko_ekp

  • Valuation Methods - foreign currency valuation

    Hello I am trying to understand the concept of different valuation methods. could you explain using examples please ? Say for instance, a goods receipt is raised in USD for 100USD on 2 Jan 2009 and local currency is EUR. Exchange rate is 1EUR : 1,5US

  • Title of the ALV report showing as SAP

    My ALV report title is displaying as 'SAP', but i have mentioned a different title 'purchase explosion' in my report(attributes section). Pls provide your inputs on this issue. Rewards will be given.

  • UnitOfWork / Update / EXCEPTION [TOPLINK-6004]

    Hello! I have an ItemObject which contains ItemLines (ValueHolder, Master-Detail). I can update the (standard)Item-Objekt attributes, but how can i set the Itemlines-Object? Should i register the Itemlines-ValueHolder in the UnitOfWork? If this is a

  • Inbox downloads 40 previously received emails everytime i open mail

    Inbox downloads 40 previously read emails every time I open mail account